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 | RegisteredExtension* RegisteredExtension::first_extension_ = NULL; |
| 476 | |
| 477 | |
| 478 | RegisteredExtension::RegisteredExtension(Extension* extension) |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 479 | : extension_(extension) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 480 | |
| 481 | |
| 482 | void RegisteredExtension::Register(RegisteredExtension* that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 483 | that->next_ = first_extension_; |
| 484 | first_extension_ = that; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 488 | void RegisteredExtension::UnregisterAll() { |
| 489 | RegisteredExtension* re = first_extension_; |
| 490 | while (re != NULL) { |
| 491 | RegisteredExtension* next = re->next(); |
| 492 | delete re; |
| 493 | re = next; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 498 | void RegisterExtension(Extension* that) { |
| 499 | RegisteredExtension* extension = new RegisteredExtension(that); |
| 500 | RegisteredExtension::Register(extension); |
| 501 | } |
| 502 | |
| 503 | |
| 504 | Extension::Extension(const char* name, |
| 505 | const char* source, |
| 506 | int dep_count, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 507 | const char** deps, |
| 508 | int source_length) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 509 | : name_(name), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 510 | source_length_(source_length >= 0 ? |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 511 | source_length : |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 512 | (source ? static_cast<int>(strlen(source)) : 0)), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 513 | source_(source, source_length_), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 514 | dep_count_(dep_count), |
| 515 | deps_(deps), |
danno@chromium.org | 412fa51 | 2012-09-14 13:28:26 +0000 | [diff] [blame] | 516 | auto_enable_(false) { |
| 517 | CHECK(source != NULL || source_length_ == 0); |
| 518 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 519 | |
| 520 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 521 | ResourceConstraints::ResourceConstraints() |
| 522 | : max_young_space_size_(0), |
| 523 | max_old_space_size_(0), |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 524 | max_executable_size_(0), |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 525 | stack_limit_(NULL), |
| 526 | max_available_threads_(0) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 527 | |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 528 | void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory, |
| 529 | uint32_t number_of_processors) { |
machenbach@chromium.org | feecfde | 2013-11-14 10:55:00 +0000 | [diff] [blame] | 530 | const int lump_of_memory = (i::kPointerSize / 4) * i::MB; |
| 531 | #if V8_OS_ANDROID |
| 532 | // Android has higher physical memory requirements before raising the maximum |
| 533 | // heap size limits since it has no swap space. |
| 534 | const uint64_t low_limit = 512ul * i::MB; |
| 535 | const uint64_t medium_limit = 1ul * i::GB; |
| 536 | const uint64_t high_limit = 2ul * i::GB; |
| 537 | #else |
| 538 | const uint64_t low_limit = 512ul * i::MB; |
| 539 | const uint64_t medium_limit = 768ul * i::MB; |
| 540 | const uint64_t high_limit = 1ul * i::GB; |
| 541 | #endif |
| 542 | |
| 543 | // The young_space_size should be a power of 2 and old_generation_size should |
| 544 | // be a multiple of Page::kPageSize. |
| 545 | if (physical_memory <= low_limit) { |
| 546 | set_max_young_space_size(2 * lump_of_memory); |
| 547 | set_max_old_space_size(128 * lump_of_memory); |
| 548 | set_max_executable_size(96 * lump_of_memory); |
| 549 | } else if (physical_memory <= medium_limit) { |
| 550 | set_max_young_space_size(8 * lump_of_memory); |
| 551 | set_max_old_space_size(256 * lump_of_memory); |
| 552 | set_max_executable_size(192 * lump_of_memory); |
| 553 | } else if (physical_memory <= high_limit) { |
| 554 | set_max_young_space_size(16 * lump_of_memory); |
| 555 | set_max_old_space_size(512 * lump_of_memory); |
| 556 | set_max_executable_size(256 * lump_of_memory); |
| 557 | } else { |
| 558 | set_max_young_space_size(16 * lump_of_memory); |
| 559 | set_max_old_space_size(700 * lump_of_memory); |
| 560 | set_max_executable_size(256 * lump_of_memory); |
| 561 | } |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 562 | |
| 563 | set_max_available_threads(i::Max(i::Min(number_of_processors, 4u), 1u)); |
| 564 | } |
| 565 | |
| 566 | |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 567 | bool SetResourceConstraints(Isolate* v8_isolate, |
| 568 | ResourceConstraints* constraints) { |
| 569 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 570 | int young_space_size = constraints->max_young_space_size(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 571 | int old_gen_size = constraints->max_old_space_size(); |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 572 | int max_executable_size = constraints->max_executable_size(); |
| 573 | 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] | 574 | // After initialization it's too late to change Heap constraints. |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 575 | ASSERT(!isolate->IsInitialized()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 576 | bool result = isolate->heap()->ConfigureHeap(young_space_size / 2, |
| 577 | old_gen_size, |
| 578 | max_executable_size); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 579 | if (!result) return false; |
| 580 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 581 | if (constraints->stack_limit() != NULL) { |
| 582 | uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 583 | isolate->stack_guard()->SetStackLimit(limit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 584 | } |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 585 | |
| 586 | isolate->set_max_available_threads(constraints->max_available_threads()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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, |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 612 | WeakCallback weak_callback) { |
| 613 | i::GlobalHandles::MakeWeak(object, parameters, weak_callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 617 | void V8::ClearWeak(i::Object** obj) { |
| 618 | i::GlobalHandles::ClearWeakness(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 622 | void V8::DisposeGlobal(i::Object** obj) { |
| 623 | i::GlobalHandles::Destroy(obj); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 624 | } |
| 625 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 626 | |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 627 | void V8::Eternalize(Isolate* v8_isolate, Value* value, int* index) { |
| 628 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 629 | i::Object* object = *Utils::OpenHandle(value); |
| 630 | isolate->eternal_handles()->Create(isolate, object, index); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 634 | Local<Value> V8::GetEternal(Isolate* v8_isolate, int index) { |
| 635 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 636 | return Utils::ToLocal(isolate->eternal_handles()->Get(index)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 640 | // --- H a n d l e s --- |
| 641 | |
| 642 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 643 | HandleScope::HandleScope(Isolate* isolate) { |
| 644 | Initialize(isolate); |
| 645 | } |
| 646 | |
| 647 | |
| 648 | void HandleScope::Initialize(Isolate* isolate) { |
| 649 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 650 | API_ENTRY_CHECK(internal_isolate, "HandleScope::HandleScope"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 651 | v8::ImplementationUtilities::HandleScopeData* current = |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 652 | internal_isolate->handle_scope_data(); |
| 653 | isolate_ = internal_isolate; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 654 | prev_next_ = current->next; |
| 655 | prev_limit_ = current->limit; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 656 | current->level++; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | |
| 660 | HandleScope::~HandleScope() { |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 661 | i::HandleScope::CloseScope(isolate_, prev_next_, prev_limit_); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 665 | int HandleScope::NumberOfHandles() { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 666 | i::Isolate* isolate = i::Isolate::Current(); |
| 667 | if (!EnsureInitializedForIsolate(isolate, "HandleScope::NumberOfHandles")) { |
| 668 | return 0; |
| 669 | } |
| 670 | return i::HandleScope::NumberOfHandles(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 674 | i::Object** HandleScope::CreateHandle(i::Isolate* isolate, i::Object* value) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 675 | return i::HandleScope::CreateHandle(isolate, value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 679 | i::Object** HandleScope::CreateHandle(i::HeapObject* heap_object, |
| 680 | i::Object* value) { |
| 681 | ASSERT(heap_object->IsHeapObject()); |
| 682 | return i::HandleScope::CreateHandle(heap_object->GetIsolate(), value); |
| 683 | } |
| 684 | |
| 685 | |
| 686 | EscapableHandleScope::EscapableHandleScope(Isolate* v8_isolate) { |
| 687 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 688 | escape_slot_ = CreateHandle(isolate, isolate->heap()->the_hole_value()); |
| 689 | Initialize(v8_isolate); |
| 690 | } |
| 691 | |
| 692 | |
| 693 | i::Object** EscapableHandleScope::Escape(i::Object** escape_value) { |
| 694 | ApiCheck(*escape_slot_ == isolate_->heap()->the_hole_value(), |
| 695 | "EscapeableHandleScope::Escape", |
| 696 | "Escape value set twice"); |
| 697 | if (escape_value == NULL) { |
| 698 | *escape_slot_ = isolate_->heap()->undefined_value(); |
| 699 | return NULL; |
| 700 | } |
| 701 | *escape_slot_ = *escape_value; |
| 702 | return escape_slot_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | |
| 706 | void Context::Enter() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 707 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 708 | i::Isolate* isolate = env->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 709 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 710 | isolate->handle_scope_implementer()->EnterContext(env); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 711 | isolate->handle_scope_implementer()->SaveContext(isolate->context()); |
| 712 | isolate->set_context(*env); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | |
| 716 | void Context::Exit() { |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 717 | // TODO(dcarney): fix this once chrome is fixed. |
| 718 | i::Isolate* isolate = i::Isolate::Current(); |
| 719 | i::Handle<i::Context> context = i::Handle<i::Context>::null(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 720 | ENTER_V8(isolate); |
| 721 | if (!ApiCheck(isolate->handle_scope_implementer()->LeaveContext(context), |
kasper.lund | 4451067 | 2008-07-25 07:37:58 +0000 | [diff] [blame] | 722 | "v8::Context::Exit()", |
| 723 | "Cannot exit non-entered context")) { |
| 724 | return; |
| 725 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 726 | // Content of 'last_context' could be NULL. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 727 | i::Context* last_context = |
| 728 | isolate->handle_scope_implementer()->RestoreContext(); |
| 729 | isolate->set_context(last_context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 733 | static void* DecodeSmiToAligned(i::Object* value, const char* location) { |
| 734 | ApiCheck(value->IsSmi(), location, "Not a Smi"); |
| 735 | return reinterpret_cast<void*>(value); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | |
mstarzinger@chromium.org | 0c977e0 | 2013-07-26 10:45:47 +0000 | [diff] [blame] | 739 | static i::Smi* EncodeAlignedAsSmi(void* value, const char* location) { |
| 740 | i::Smi* smi = reinterpret_cast<i::Smi*>(value); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 741 | ApiCheck(smi->IsSmi(), location, "Pointer is not aligned"); |
| 742 | return smi; |
| 743 | } |
| 744 | |
| 745 | |
| 746 | static i::Handle<i::FixedArray> EmbedderDataFor(Context* context, |
| 747 | int index, |
| 748 | bool can_grow, |
| 749 | const char* location) { |
| 750 | i::Handle<i::Context> env = Utils::OpenHandle(context); |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 751 | bool ok = |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 752 | ApiCheck(env->IsNativeContext(), location, "Not a native context") && |
| 753 | ApiCheck(index >= 0, location, "Negative index"); |
| 754 | if (!ok) return i::Handle<i::FixedArray>(); |
| 755 | i::Handle<i::FixedArray> data(env->embedder_data()); |
| 756 | if (index < data->length()) return data; |
| 757 | if (!can_grow) { |
| 758 | Utils::ReportApiFailure(location, "Index too large"); |
| 759 | return i::Handle<i::FixedArray>(); |
svenpanne@chromium.org | fc2a4f4 | 2012-11-07 09:25:55 +0000 | [diff] [blame] | 760 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 761 | int new_size = i::Max(index, data->length() << 1) + 1; |
| 762 | data = env->GetIsolate()->factory()->CopySizeFixedArray(data, new_size); |
| 763 | env->set_embedder_data(*data); |
| 764 | return data; |
| 765 | } |
| 766 | |
| 767 | |
| 768 | v8::Local<v8::Value> Context::SlowGetEmbedderData(int index) { |
| 769 | const char* location = "v8::Context::GetEmbedderData()"; |
| 770 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location); |
| 771 | if (data.is_null()) return Local<Value>(); |
| 772 | i::Handle<i::Object> result(data->get(index), data->GetIsolate()); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 773 | return Utils::ToLocal(result); |
| 774 | } |
| 775 | |
| 776 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 777 | void Context::SetEmbedderData(int index, v8::Handle<Value> value) { |
| 778 | const char* location = "v8::Context::SetEmbedderData()"; |
| 779 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, true, location); |
| 780 | if (data.is_null()) return; |
| 781 | i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 782 | data->set(index, *val); |
| 783 | ASSERT_EQ(*Utils::OpenHandle(*value), |
| 784 | *Utils::OpenHandle(*GetEmbedderData(index))); |
| 785 | } |
| 786 | |
| 787 | |
| 788 | void* Context::SlowGetAlignedPointerFromEmbedderData(int index) { |
| 789 | const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()"; |
| 790 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location); |
| 791 | if (data.is_null()) return NULL; |
| 792 | return DecodeSmiToAligned(data->get(index), location); |
| 793 | } |
| 794 | |
| 795 | |
| 796 | void Context::SetAlignedPointerInEmbedderData(int index, void* value) { |
| 797 | const char* location = "v8::Context::SetAlignedPointerInEmbedderData()"; |
| 798 | i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, true, location); |
| 799 | data->set(index, EncodeAlignedAsSmi(value, location)); |
| 800 | ASSERT_EQ(value, GetAlignedPointerFromEmbedderData(index)); |
| 801 | } |
| 802 | |
| 803 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 804 | // --- N e a n d e r --- |
| 805 | |
| 806 | |
| 807 | // A constructor cannot easily return an error value, therefore it is necessary |
| 808 | // to check for a dead VM with ON_BAILOUT before constructing any Neander |
| 809 | // objects. To remind you about this there is no HandleScope in the |
| 810 | // NeanderObject constructor. When you add one to the site calling the |
| 811 | // constructor you should check that you ensured the VM was not dead first. |
| 812 | NeanderObject::NeanderObject(int size) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 813 | i::Isolate* isolate = i::Isolate::Current(); |
| 814 | EnsureInitializedForIsolate(isolate, "v8::Nowhere"); |
| 815 | ENTER_V8(isolate); |
| 816 | value_ = isolate->factory()->NewNeanderObject(); |
| 817 | i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 818 | value_->set_elements(*elements); |
| 819 | } |
| 820 | |
| 821 | |
| 822 | int NeanderObject::size() { |
| 823 | return i::FixedArray::cast(value_->elements())->length(); |
| 824 | } |
| 825 | |
| 826 | |
| 827 | NeanderArray::NeanderArray() : obj_(2) { |
| 828 | obj_.set(0, i::Smi::FromInt(0)); |
| 829 | } |
| 830 | |
| 831 | |
| 832 | int NeanderArray::length() { |
| 833 | return i::Smi::cast(obj_.get(0))->value(); |
| 834 | } |
| 835 | |
| 836 | |
| 837 | i::Object* NeanderArray::get(int offset) { |
| 838 | ASSERT(0 <= offset); |
| 839 | ASSERT(offset < length()); |
| 840 | return obj_.get(offset + 1); |
| 841 | } |
| 842 | |
| 843 | |
| 844 | // This method cannot easily return an error value, therefore it is necessary |
| 845 | // to check for a dead VM with ON_BAILOUT before calling it. To remind you |
| 846 | // about this there is no HandleScope in this method. When you add one to the |
| 847 | // site calling this method you should check that you ensured the VM was not |
| 848 | // dead first. |
| 849 | void NeanderArray::add(i::Handle<i::Object> value) { |
| 850 | int length = this->length(); |
| 851 | int size = obj_.size(); |
| 852 | if (length == size - 1) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 853 | i::Factory* factory = i::Isolate::Current()->factory(); |
| 854 | i::Handle<i::FixedArray> new_elms = factory->NewFixedArray(2 * size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 855 | for (int i = 0; i < length; i++) |
| 856 | new_elms->set(i + 1, get(i)); |
| 857 | obj_.value()->set_elements(*new_elms); |
| 858 | } |
| 859 | obj_.set(length + 1, *value); |
| 860 | obj_.set(0, i::Smi::FromInt(length + 1)); |
| 861 | } |
| 862 | |
| 863 | |
| 864 | void NeanderArray::set(int index, i::Object* value) { |
| 865 | if (index < 0 || index >= this->length()) return; |
| 866 | obj_.set(index + 1, value); |
| 867 | } |
| 868 | |
| 869 | |
| 870 | // --- T e m p l a t e --- |
| 871 | |
| 872 | |
| 873 | static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { |
| 874 | that->set_tag(i::Smi::FromInt(type)); |
| 875 | } |
| 876 | |
| 877 | |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 878 | static void TemplateSet(i::Isolate* isolate, |
| 879 | v8::Template* templ, |
| 880 | int length, |
| 881 | v8::Handle<v8::Data>* data) { |
| 882 | i::Handle<i::Object> list(Utils::OpenHandle(templ)->property_list(), isolate); |
| 883 | if (list->IsUndefined()) { |
| 884 | list = NeanderArray().value(); |
| 885 | Utils::OpenHandle(templ)->set_property_list(*list); |
| 886 | } |
| 887 | NeanderArray array(list); |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 888 | array.add(isolate->factory()->NewNumberFromInt(length)); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 889 | for (int i = 0; i < length; i++) { |
| 890 | i::Handle<i::Object> value = data[i].IsEmpty() ? |
| 891 | i::Handle<i::Object>(isolate->factory()->undefined_value()) : |
| 892 | Utils::OpenHandle(*data[i]); |
| 893 | array.add(value); |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | |
| 898 | void Template::Set(v8::Handle<String> name, |
| 899 | v8::Handle<Data> value, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 900 | v8::PropertyAttribute attribute) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 901 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 902 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 903 | i::HandleScope scope(isolate); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 904 | const int kSize = 3; |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 905 | v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 906 | v8::Handle<v8::Data> data[kSize] = { |
| 907 | name, |
| 908 | value, |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 909 | v8::Integer::New(v8_isolate, attribute)}; |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 910 | TemplateSet(isolate, this, kSize, data); |
| 911 | } |
| 912 | |
| 913 | |
| 914 | void Template::SetAccessorProperty( |
| 915 | v8::Local<v8::String> name, |
| 916 | v8::Local<FunctionTemplate> getter, |
| 917 | v8::Local<FunctionTemplate> setter, |
| 918 | v8::PropertyAttribute attribute, |
| 919 | v8::AccessControl access_control) { |
| 920 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 921 | ENTER_V8(isolate); |
| 922 | ASSERT(!name.IsEmpty()); |
| 923 | ASSERT(!getter.IsEmpty() || !setter.IsEmpty()); |
| 924 | i::HandleScope scope(isolate); |
| 925 | const int kSize = 5; |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 926 | v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 927 | v8::Handle<v8::Data> data[kSize] = { |
| 928 | name, |
| 929 | getter, |
| 930 | setter, |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 931 | v8::Integer::New(v8_isolate, attribute), |
| 932 | v8::Integer::New(v8_isolate, access_control)}; |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 933 | TemplateSet(isolate, this, kSize, data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | |
| 937 | // --- F u n c t i o n T e m p l a t e --- |
| 938 | static void InitializeFunctionTemplate( |
| 939 | i::Handle<i::FunctionTemplateInfo> info) { |
| 940 | info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE)); |
| 941 | info->set_flag(0); |
| 942 | } |
| 943 | |
| 944 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 945 | Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 946 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 947 | ENTER_V8(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 948 | i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(), |
| 949 | isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 950 | if (result->IsUndefined()) { |
| 951 | result = Utils::OpenHandle(*ObjectTemplate::New()); |
| 952 | Utils::OpenHandle(this)->set_prototype_template(*result); |
| 953 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 954 | return ToApiHandle<ObjectTemplate>(result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | |
| 958 | void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 959 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 960 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 961 | Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); |
| 962 | } |
| 963 | |
| 964 | |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 965 | static Local<FunctionTemplate> FunctionTemplateNew( |
| 966 | i::Isolate* isolate, |
| 967 | FunctionCallback callback, |
| 968 | v8::Handle<Value> data, |
| 969 | v8::Handle<Signature> signature, |
| 970 | int length, |
| 971 | bool do_not_cache) { |
| 972 | i::Handle<i::Struct> struct_obj = |
| 973 | isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
| 974 | i::Handle<i::FunctionTemplateInfo> obj = |
| 975 | i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
| 976 | InitializeFunctionTemplate(obj); |
| 977 | obj->set_do_not_cache(do_not_cache); |
| 978 | int next_serial_number = 0; |
| 979 | if (!do_not_cache) { |
| 980 | next_serial_number = isolate->next_serial_number() + 1; |
| 981 | isolate->set_next_serial_number(next_serial_number); |
| 982 | } |
| 983 | obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
| 984 | if (callback != 0) { |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 985 | if (data.IsEmpty()) { |
| 986 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 987 | } |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 988 | Utils::ToLocal(obj)->SetCallHandler(callback, data); |
| 989 | } |
| 990 | obj->set_length(length); |
| 991 | obj->set_undetectable(false); |
| 992 | obj->set_needs_access_check(false); |
| 993 | if (!signature.IsEmpty()) |
| 994 | obj->set_signature(*Utils::OpenHandle(*signature)); |
| 995 | return Utils::ToLocal(obj); |
| 996 | } |
| 997 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 998 | Local<FunctionTemplate> FunctionTemplate::New( |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 999 | Isolate* isolate, |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1000 | FunctionCallback callback, |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1001 | v8::Handle<Value> data, |
| 1002 | v8::Handle<Signature> signature, |
| 1003 | int length) { |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1004 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1005 | EnsureInitializedForIsolate(i_isolate, "v8::FunctionTemplate::New()"); |
| 1006 | LOG_API(i_isolate, "FunctionTemplate::New"); |
| 1007 | ENTER_V8(i_isolate); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 1008 | return FunctionTemplateNew( |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1009 | i_isolate, callback, data, signature, length, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1013 | Local<Signature> Signature::New(Isolate* isolate, |
| 1014 | Handle<FunctionTemplate> receiver, int argc, |
| 1015 | Handle<FunctionTemplate> argv[]) { |
| 1016 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1017 | EnsureInitializedForIsolate(i_isolate, "v8::Signature::New()"); |
| 1018 | LOG_API(i_isolate, "Signature::New"); |
| 1019 | ENTER_V8(i_isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1020 | i::Handle<i::Struct> struct_obj = |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1021 | i_isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1022 | i::Handle<i::SignatureInfo> obj = |
| 1023 | i::Handle<i::SignatureInfo>::cast(struct_obj); |
| 1024 | if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver)); |
| 1025 | if (argc > 0) { |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1026 | i::Handle<i::FixedArray> args = i_isolate->factory()->NewFixedArray(argc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1027 | for (int i = 0; i < argc; i++) { |
| 1028 | if (!argv[i].IsEmpty()) |
| 1029 | args->set(i, *Utils::OpenHandle(*argv[i])); |
| 1030 | } |
| 1031 | obj->set_args(*args); |
| 1032 | } |
| 1033 | return Utils::ToLocal(obj); |
| 1034 | } |
| 1035 | |
| 1036 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1037 | Local<AccessorSignature> AccessorSignature::New( |
| 1038 | Isolate* isolate, |
| 1039 | Handle<FunctionTemplate> receiver) { |
| 1040 | return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); |
| 1041 | } |
| 1042 | |
| 1043 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1044 | template<typename Operation> |
| 1045 | static Local<Operation> NewDescriptor( |
| 1046 | Isolate* isolate, |
| 1047 | const i::DeclaredAccessorDescriptorData& data, |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1048 | Data* previous_descriptor) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1049 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1050 | i::Handle<i::DeclaredAccessorDescriptor> previous = |
| 1051 | i::Handle<i::DeclaredAccessorDescriptor>(); |
| 1052 | if (previous_descriptor != NULL) { |
| 1053 | previous = Utils::OpenHandle( |
| 1054 | static_cast<DeclaredAccessorDescriptor*>(previous_descriptor)); |
| 1055 | } |
| 1056 | i::Handle<i::DeclaredAccessorDescriptor> descriptor = |
| 1057 | i::DeclaredAccessorDescriptor::Create(internal_isolate, data, previous); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1058 | return Utils::Convert<i::DeclaredAccessorDescriptor, Operation>(descriptor); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | |
| 1062 | Local<RawOperationDescriptor> |
| 1063 | ObjectOperationDescriptor::NewInternalFieldDereference( |
| 1064 | Isolate* isolate, |
| 1065 | int internal_field) { |
| 1066 | i::DeclaredAccessorDescriptorData data; |
| 1067 | data.type = i::kDescriptorObjectDereference; |
| 1068 | data.object_dereference_descriptor.internal_field = internal_field; |
| 1069 | return NewDescriptor<RawOperationDescriptor>(isolate, data, NULL); |
| 1070 | } |
| 1071 | |
| 1072 | |
| 1073 | Local<RawOperationDescriptor> RawOperationDescriptor::NewRawShift( |
| 1074 | Isolate* isolate, |
| 1075 | int16_t byte_offset) { |
| 1076 | i::DeclaredAccessorDescriptorData data; |
| 1077 | data.type = i::kDescriptorPointerShift; |
| 1078 | data.pointer_shift_descriptor.byte_offset = byte_offset; |
| 1079 | return NewDescriptor<RawOperationDescriptor>(isolate, data, this); |
| 1080 | } |
| 1081 | |
| 1082 | |
| 1083 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewHandleDereference( |
| 1084 | Isolate* isolate) { |
| 1085 | i::DeclaredAccessorDescriptorData data; |
| 1086 | data.type = i::kDescriptorReturnObject; |
| 1087 | return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this); |
| 1088 | } |
| 1089 | |
| 1090 | |
| 1091 | Local<RawOperationDescriptor> RawOperationDescriptor::NewRawDereference( |
| 1092 | Isolate* isolate) { |
| 1093 | i::DeclaredAccessorDescriptorData data; |
| 1094 | data.type = i::kDescriptorPointerDereference; |
| 1095 | return NewDescriptor<RawOperationDescriptor>(isolate, data, this); |
| 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewPointerCompare( |
| 1100 | Isolate* isolate, |
| 1101 | void* compare_value) { |
| 1102 | i::DeclaredAccessorDescriptorData data; |
| 1103 | data.type = i::kDescriptorPointerCompare; |
| 1104 | data.pointer_compare_descriptor.compare_value = compare_value; |
| 1105 | return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this); |
| 1106 | } |
| 1107 | |
| 1108 | |
| 1109 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewPrimitiveValue( |
| 1110 | Isolate* isolate, |
| 1111 | DeclaredAccessorDescriptorDataType data_type, |
| 1112 | uint8_t bool_offset) { |
| 1113 | i::DeclaredAccessorDescriptorData data; |
| 1114 | data.type = i::kDescriptorPrimitiveValue; |
| 1115 | data.primitive_value_descriptor.data_type = data_type; |
| 1116 | data.primitive_value_descriptor.bool_offset = bool_offset; |
| 1117 | return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this); |
| 1118 | } |
| 1119 | |
| 1120 | |
| 1121 | template<typename T> |
| 1122 | static Local<DeclaredAccessorDescriptor> NewBitmaskCompare( |
| 1123 | Isolate* isolate, |
| 1124 | T bitmask, |
| 1125 | T compare_value, |
| 1126 | RawOperationDescriptor* operation) { |
| 1127 | i::DeclaredAccessorDescriptorData data; |
| 1128 | data.type = i::kDescriptorBitmaskCompare; |
| 1129 | data.bitmask_compare_descriptor.bitmask = bitmask; |
| 1130 | data.bitmask_compare_descriptor.compare_value = compare_value; |
| 1131 | data.bitmask_compare_descriptor.size = sizeof(T); |
| 1132 | return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, operation); |
| 1133 | } |
| 1134 | |
| 1135 | |
| 1136 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare8( |
| 1137 | Isolate* isolate, |
| 1138 | uint8_t bitmask, |
| 1139 | uint8_t compare_value) { |
| 1140 | return NewBitmaskCompare(isolate, bitmask, compare_value, this); |
| 1141 | } |
| 1142 | |
| 1143 | |
| 1144 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare16( |
| 1145 | Isolate* isolate, |
| 1146 | uint16_t bitmask, |
| 1147 | uint16_t compare_value) { |
| 1148 | return NewBitmaskCompare(isolate, bitmask, compare_value, this); |
| 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare32( |
| 1153 | Isolate* isolate, |
| 1154 | uint32_t bitmask, |
| 1155 | uint32_t compare_value) { |
| 1156 | return NewBitmaskCompare(isolate, bitmask, compare_value, this); |
| 1157 | } |
| 1158 | |
| 1159 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1160 | Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) { |
| 1161 | Handle<FunctionTemplate> types[1] = { type }; |
| 1162 | return TypeSwitch::New(1, types); |
| 1163 | } |
| 1164 | |
| 1165 | |
| 1166 | Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1167 | i::Isolate* isolate = i::Isolate::Current(); |
| 1168 | EnsureInitializedForIsolate(isolate, "v8::TypeSwitch::New()"); |
| 1169 | LOG_API(isolate, "TypeSwitch::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1170 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1171 | i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1172 | for (int i = 0; i < argc; i++) |
| 1173 | vector->set(i, *Utils::OpenHandle(*types[i])); |
| 1174 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1175 | isolate->factory()->NewStruct(i::TYPE_SWITCH_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1176 | i::Handle<i::TypeSwitchInfo> obj = |
| 1177 | i::Handle<i::TypeSwitchInfo>::cast(struct_obj); |
| 1178 | obj->set_types(*vector); |
| 1179 | return Utils::ToLocal(obj); |
| 1180 | } |
| 1181 | |
| 1182 | |
| 1183 | int TypeSwitch::match(v8::Handle<Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1184 | i::Isolate* isolate = i::Isolate::Current(); |
| 1185 | LOG_API(isolate, "TypeSwitch::match"); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1186 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1187 | i::Handle<i::Object> obj = Utils::OpenHandle(*value); |
| 1188 | i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this); |
| 1189 | i::FixedArray* types = i::FixedArray::cast(info->types()); |
| 1190 | for (int i = 0; i < types->length(); i++) { |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 1191 | if (i::FunctionTemplateInfo::cast(types->get(i))->IsTemplateFor(*obj)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1192 | return i + 1; |
| 1193 | } |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
| 1197 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1198 | #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 1199 | i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1200 | (obj)->setter(*foreign); \ |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1201 | } while (false) |
| 1202 | |
| 1203 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1204 | void FunctionTemplate::SetCallHandler(FunctionCallback callback, |
| 1205 | v8::Handle<Value> data) { |
| 1206 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1207 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1208 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1209 | i::Handle<i::Struct> struct_obj = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1210 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1211 | i::Handle<i::CallHandlerInfo> obj = |
| 1212 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1213 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1214 | if (data.IsEmpty()) { |
| 1215 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1216 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1217 | obj->set_data(*Utils::OpenHandle(*data)); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1218 | Utils::OpenHandle(this)->set_call_code(*obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1222 | static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( |
| 1223 | i::Handle<i::AccessorInfo> obj, |
| 1224 | v8::Handle<String> name, |
| 1225 | v8::AccessControl settings, |
| 1226 | v8::PropertyAttribute attributes, |
| 1227 | v8::Handle<AccessorSignature> signature) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1228 | obj->set_name(*Utils::OpenHandle(*name)); |
| 1229 | if (settings & ALL_CAN_READ) obj->set_all_can_read(true); |
| 1230 | if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); |
| 1231 | if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true); |
| 1232 | obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1233 | if (!signature.IsEmpty()) { |
| 1234 | obj->set_expected_receiver_type(*Utils::OpenHandle(*signature)); |
| 1235 | } |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1236 | return obj; |
| 1237 | } |
| 1238 | |
| 1239 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1240 | template<typename Getter, typename Setter> |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1241 | static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1242 | v8::Handle<String> name, |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1243 | Getter getter, |
| 1244 | Setter setter, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1245 | v8::Handle<Value> data, |
| 1246 | v8::AccessControl settings, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1247 | v8::PropertyAttribute attributes, |
| 1248 | v8::Handle<AccessorSignature> signature) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1249 | i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate(); |
| 1250 | i::Handle<i::ExecutableAccessorInfo> obj = |
| 1251 | isolate->factory()->NewExecutableAccessorInfo(); |
| 1252 | SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1253 | SET_FIELD_WRAPPED(obj, set_setter, setter); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1254 | if (data.IsEmpty()) { |
| 1255 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1256 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1257 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1258 | return SetAccessorInfoProperties(obj, name, settings, attributes, signature); |
| 1259 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1260 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1261 | |
| 1262 | static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
| 1263 | v8::Handle<String> name, |
| 1264 | v8::Handle<v8::DeclaredAccessorDescriptor> descriptor, |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1265 | void* setter_ignored, |
| 1266 | void* data_ignored, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1267 | v8::AccessControl settings, |
| 1268 | v8::PropertyAttribute attributes, |
| 1269 | v8::Handle<AccessorSignature> signature) { |
| 1270 | i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate(); |
| 1271 | if (descriptor.IsEmpty()) return i::Handle<i::DeclaredAccessorInfo>(); |
| 1272 | i::Handle<i::DeclaredAccessorInfo> obj = |
| 1273 | isolate->factory()->NewDeclaredAccessorInfo(); |
| 1274 | obj->set_descriptor(*Utils::OpenHandle(*descriptor)); |
| 1275 | return SetAccessorInfoProperties(obj, name, settings, attributes, signature); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | |
| 1279 | Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1280 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 1281 | if (EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1282 | return Local<ObjectTemplate>(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1283 | ENTER_V8(isolate); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1284 | i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this); |
| 1285 | if (handle->instance_template()->IsUndefined()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1286 | Local<ObjectTemplate> templ = |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1287 | ObjectTemplate::New(isolate, ToApiHandle<FunctionTemplate>(handle)); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1288 | handle->set_instance_template(*Utils::OpenHandle(*templ)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1289 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1290 | i::Handle<i::ObjectTemplateInfo> result( |
| 1291 | i::ObjectTemplateInfo::cast(handle->instance_template())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1292 | return Utils::ToLocal(result); |
| 1293 | } |
| 1294 | |
| 1295 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1296 | void FunctionTemplate::SetLength(int length) { |
| 1297 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1298 | ENTER_V8(isolate); |
| 1299 | Utils::OpenHandle(this)->set_length(length); |
| 1300 | } |
| 1301 | |
| 1302 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1303 | void FunctionTemplate::SetClassName(Handle<String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1304 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1305 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1306 | Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name)); |
| 1307 | } |
| 1308 | |
| 1309 | |
| 1310 | void FunctionTemplate::SetHiddenPrototype(bool value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1311 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1312 | ENTER_V8(isolate); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1313 | Utils::OpenHandle(this)->set_hidden_prototype(value); |
| 1314 | } |
| 1315 | |
| 1316 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1317 | void FunctionTemplate::ReadOnlyPrototype() { |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1318 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1319 | ENTER_V8(isolate); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1320 | Utils::OpenHandle(this)->set_read_only_prototype(true); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1323 | |
| 1324 | void FunctionTemplate::RemovePrototype() { |
| 1325 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1326 | ENTER_V8(isolate); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1327 | Utils::OpenHandle(this)->set_remove_prototype(true); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1331 | // --- O b j e c t T e m p l a t e --- |
| 1332 | |
| 1333 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1334 | Local<ObjectTemplate> ObjectTemplate::New(Isolate* isolate) { |
| 1335 | return New(reinterpret_cast<i::Isolate*>(isolate), Local<FunctionTemplate>()); |
| 1336 | } |
| 1337 | |
| 1338 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1339 | Local<ObjectTemplate> ObjectTemplate::New() { |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1340 | return New(i::Isolate::Current(), Local<FunctionTemplate>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | |
| 1344 | Local<ObjectTemplate> ObjectTemplate::New( |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1345 | i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1346 | v8::Handle<FunctionTemplate> constructor) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1347 | EnsureInitializedForIsolate(isolate, "v8::ObjectTemplate::New()"); |
| 1348 | LOG_API(isolate, "ObjectTemplate::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1349 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1350 | i::Handle<i::Struct> struct_obj = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1351 | isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1352 | i::Handle<i::ObjectTemplateInfo> obj = |
| 1353 | i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); |
| 1354 | InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
| 1355 | if (!constructor.IsEmpty()) |
| 1356 | obj->set_constructor(*Utils::OpenHandle(*constructor)); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1357 | obj->set_internal_field_count(i::Smi::FromInt(0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1358 | return Utils::ToLocal(obj); |
| 1359 | } |
| 1360 | |
| 1361 | |
| 1362 | // Ensure that the object template has a constructor. If no |
| 1363 | // constructor is available we create one. |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1364 | static i::Handle<i::FunctionTemplateInfo> EnsureConstructor( |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1365 | i::Isolate* isolate, |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1366 | ObjectTemplate* object_template) { |
| 1367 | i::Object* obj = Utils::OpenHandle(object_template)->constructor(); |
| 1368 | if (!obj ->IsUndefined()) { |
| 1369 | i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1370 | return i::Handle<i::FunctionTemplateInfo>(info, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1371 | } |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1372 | Local<FunctionTemplate> templ = |
| 1373 | FunctionTemplate::New(reinterpret_cast<Isolate*>(isolate)); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1374 | i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); |
| 1375 | constructor->set_instance_template(*Utils::OpenHandle(object_template)); |
| 1376 | Utils::OpenHandle(object_template)->set_constructor(*constructor); |
| 1377 | return constructor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1381 | static inline void AddPropertyToTemplate( |
| 1382 | i::Handle<i::TemplateInfo> info, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1383 | i::Handle<i::AccessorInfo> obj) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1384 | i::Handle<i::Object> list(info->property_accessors(), info->GetIsolate()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1385 | if (list->IsUndefined()) { |
| 1386 | list = NeanderArray().value(); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1387 | info->set_property_accessors(*list); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1388 | } |
| 1389 | NeanderArray array(list); |
| 1390 | array.add(obj); |
| 1391 | } |
| 1392 | |
| 1393 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1394 | static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1395 | i::Isolate* isolate, |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1396 | Template* template_obj) { |
| 1397 | return Utils::OpenHandle(template_obj); |
| 1398 | } |
| 1399 | |
| 1400 | |
| 1401 | // TODO(dcarney): remove this with ObjectTemplate::SetAccessor |
| 1402 | static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1403 | i::Isolate* isolate, |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1404 | ObjectTemplate* object_template) { |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1405 | EnsureConstructor(isolate, object_template); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1406 | return Utils::OpenHandle(object_template); |
| 1407 | } |
| 1408 | |
| 1409 | |
| 1410 | template<typename Setter, typename Getter, typename Data, typename Template> |
| 1411 | static bool TemplateSetAccessor( |
| 1412 | Template* template_obj, |
| 1413 | v8::Local<String> name, |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1414 | Getter getter, |
| 1415 | Setter setter, |
| 1416 | Data data, |
| 1417 | AccessControl settings, |
| 1418 | PropertyAttribute attribute, |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1419 | v8::Local<AccessorSignature> signature) { |
| 1420 | i::Isolate* isolate = Utils::OpenHandle(template_obj)->GetIsolate(); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1421 | ENTER_V8(isolate); |
| 1422 | i::HandleScope scope(isolate); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1423 | i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( |
| 1424 | name, getter, setter, data, settings, attribute, signature); |
| 1425 | if (obj.is_null()) return false; |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1426 | i::Handle<i::TemplateInfo> info = GetTemplateInfo(isolate, template_obj); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1427 | AddPropertyToTemplate(info, obj); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1428 | return true; |
| 1429 | } |
| 1430 | |
| 1431 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1432 | bool Template::SetDeclaredAccessor( |
| 1433 | Local<String> name, |
| 1434 | Local<DeclaredAccessorDescriptor> descriptor, |
| 1435 | PropertyAttribute attribute, |
| 1436 | Local<AccessorSignature> signature, |
| 1437 | AccessControl settings) { |
| 1438 | void* null = NULL; |
| 1439 | return TemplateSetAccessor( |
| 1440 | this, name, descriptor, null, null, settings, attribute, signature); |
| 1441 | } |
| 1442 | |
| 1443 | |
| 1444 | void Template::SetNativeDataProperty(v8::Local<String> name, |
| 1445 | AccessorGetterCallback getter, |
| 1446 | AccessorSetterCallback setter, |
| 1447 | v8::Handle<Value> data, |
| 1448 | PropertyAttribute attribute, |
| 1449 | v8::Local<AccessorSignature> signature, |
| 1450 | AccessControl settings) { |
| 1451 | TemplateSetAccessor( |
| 1452 | this, name, getter, setter, data, settings, attribute, signature); |
| 1453 | } |
| 1454 | |
| 1455 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1456 | void ObjectTemplate::SetAccessor(v8::Handle<String> name, |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1457 | AccessorGetterCallback getter, |
| 1458 | AccessorSetterCallback setter, |
| 1459 | v8::Handle<Value> data, |
| 1460 | AccessControl settings, |
| 1461 | PropertyAttribute attribute, |
| 1462 | v8::Handle<AccessorSignature> signature) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1463 | TemplateSetAccessor( |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1464 | this, name, getter, setter, data, settings, attribute, signature); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1468 | void ObjectTemplate::SetNamedPropertyHandler( |
| 1469 | NamedPropertyGetterCallback getter, |
| 1470 | NamedPropertySetterCallback setter, |
| 1471 | NamedPropertyQueryCallback query, |
| 1472 | NamedPropertyDeleterCallback remover, |
| 1473 | NamedPropertyEnumeratorCallback enumerator, |
| 1474 | Handle<Value> data) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1475 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1476 | ENTER_V8(isolate); |
| 1477 | i::HandleScope scope(isolate); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1478 | EnsureConstructor(isolate, this); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1479 | i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( |
| 1480 | Utils::OpenHandle(this)->constructor()); |
| 1481 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1482 | i::Handle<i::Struct> struct_obj = |
| 1483 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
| 1484 | i::Handle<i::InterceptorInfo> obj = |
| 1485 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
| 1486 | |
| 1487 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1488 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1489 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1490 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1491 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1492 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1493 | if (data.IsEmpty()) { |
| 1494 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1495 | } |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1496 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1497 | cons->set_named_property_handler(*obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | |
| 1501 | void ObjectTemplate::MarkAsUndetectable() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1502 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1503 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1504 | i::HandleScope scope(isolate); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1505 | EnsureConstructor(isolate, this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1506 | i::FunctionTemplateInfo* constructor = |
| 1507 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1508 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1509 | cons->set_undetectable(true); |
| 1510 | } |
| 1511 | |
| 1512 | |
| 1513 | void ObjectTemplate::SetAccessCheckCallbacks( |
| 1514 | NamedSecurityCallback named_callback, |
| 1515 | IndexedSecurityCallback indexed_callback, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1516 | Handle<Value> data, |
| 1517 | bool turned_on_by_default) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1518 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1519 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1520 | i::HandleScope scope(isolate); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1521 | EnsureConstructor(isolate, this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1522 | |
| 1523 | i::Handle<i::Struct> struct_info = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1524 | isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1525 | i::Handle<i::AccessCheckInfo> info = |
| 1526 | i::Handle<i::AccessCheckInfo>::cast(struct_info); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1527 | |
| 1528 | SET_FIELD_WRAPPED(info, set_named_callback, named_callback); |
| 1529 | SET_FIELD_WRAPPED(info, set_indexed_callback, indexed_callback); |
| 1530 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1531 | if (data.IsEmpty()) { |
| 1532 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1533 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1534 | info->set_data(*Utils::OpenHandle(*data)); |
| 1535 | |
| 1536 | i::FunctionTemplateInfo* constructor = |
| 1537 | i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); |
| 1538 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1539 | cons->set_access_check_info(*info); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1540 | cons->set_needs_access_check(turned_on_by_default); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1544 | void ObjectTemplate::SetIndexedPropertyHandler( |
| 1545 | IndexedPropertyGetterCallback getter, |
| 1546 | IndexedPropertySetterCallback setter, |
| 1547 | IndexedPropertyQueryCallback query, |
| 1548 | IndexedPropertyDeleterCallback remover, |
| 1549 | IndexedPropertyEnumeratorCallback enumerator, |
| 1550 | Handle<Value> data) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1551 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1552 | ENTER_V8(isolate); |
| 1553 | i::HandleScope scope(isolate); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1554 | EnsureConstructor(isolate, this); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1555 | i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( |
| 1556 | Utils::OpenHandle(this)->constructor()); |
| 1557 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
| 1558 | i::Handle<i::Struct> struct_obj = |
| 1559 | isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); |
| 1560 | i::Handle<i::InterceptorInfo> obj = |
| 1561 | i::Handle<i::InterceptorInfo>::cast(struct_obj); |
| 1562 | |
| 1563 | if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1564 | if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1565 | if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1566 | if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1567 | if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1568 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1569 | if (data.IsEmpty()) { |
| 1570 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1571 | } |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1572 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1573 | cons->set_indexed_property_handler(*obj); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1577 | void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback, |
| 1578 | Handle<Value> data) { |
| 1579 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1580 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1581 | i::HandleScope scope(isolate); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1582 | EnsureConstructor(isolate, this); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1583 | i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1584 | Utils::OpenHandle(this)->constructor()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1585 | i::Handle<i::FunctionTemplateInfo> cons(constructor); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1586 | i::Handle<i::Struct> struct_obj = |
| 1587 | isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
| 1588 | i::Handle<i::CallHandlerInfo> obj = |
| 1589 | i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
| 1590 | SET_FIELD_WRAPPED(obj, set_callback, callback); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1591 | if (data.IsEmpty()) { |
| 1592 | data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1593 | } |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1594 | obj->set_data(*Utils::OpenHandle(*data)); |
| 1595 | cons->set_instance_call_handler(*obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1599 | int ObjectTemplate::InternalFieldCount() { |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1600 | return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1604 | void ObjectTemplate::SetInternalFieldCount(int value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1605 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1606 | if (!ApiCheck(i::Smi::IsValid(value), |
| 1607 | "v8::ObjectTemplate::SetInternalFieldCount()", |
| 1608 | "Invalid internal field count")) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1609 | return; |
| 1610 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1611 | ENTER_V8(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1612 | if (value > 0) { |
| 1613 | // The internal field count is set by the constructor function's |
| 1614 | // construct code, so we ensure that there is a constructor |
| 1615 | // function to do the setting. |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1616 | EnsureConstructor(isolate, this); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1617 | } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1618 | Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1622 | // --- S c r i p t D a t a --- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1623 | |
| 1624 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1625 | ScriptData* ScriptData::PreCompile(v8::Isolate* isolate, |
| 1626 | const char* input, |
| 1627 | int length) { |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1628 | i::Utf8ToUtf16CharacterStream stream( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1629 | reinterpret_cast<const unsigned char*>(input), length); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1630 | return i::PreParserApi::PreParse( |
| 1631 | reinterpret_cast<i::Isolate*>(isolate), &stream); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1635 | ScriptData* ScriptData::PreCompile(v8::Handle<String> source) { |
| 1636 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1637 | i::Isolate* isolate = str->GetIsolate(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1638 | if (str->IsExternalTwoByteString()) { |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1639 | i::ExternalTwoByteStringUtf16CharacterStream stream( |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1640 | i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length()); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1641 | return i::PreParserApi::PreParse(isolate, &stream); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1642 | } else { |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1643 | i::GenericStringUtf16CharacterStream stream(str, 0, str->length()); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 1644 | return i::PreParserApi::PreParse(isolate, &stream); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1645 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1649 | ScriptData* ScriptData::New(const char* data, int length) { |
| 1650 | // Return an empty ScriptData if the length is obviously invalid. |
| 1651 | if (length % sizeof(unsigned) != 0) { |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1652 | return new i::ScriptDataImpl(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | // Copy the data to ensure it is properly aligned. |
| 1656 | int deserialized_data_length = length / sizeof(unsigned); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 1657 | // If aligned, don't create a copy of the data. |
| 1658 | if (reinterpret_cast<intptr_t>(data) % sizeof(unsigned) == 0) { |
| 1659 | return new i::ScriptDataImpl(data, length); |
| 1660 | } |
| 1661 | // Copy the data to align it. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1662 | unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1663 | i::CopyBytes(reinterpret_cast<char*>(deserialized_data), |
| 1664 | data, static_cast<size_t>(length)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1665 | |
| 1666 | return new i::ScriptDataImpl( |
| 1667 | i::Vector<unsigned>(deserialized_data, deserialized_data_length)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | |
| 1671 | // --- S c r i p t --- |
| 1672 | |
| 1673 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1674 | Local<Script> Script::New(v8::Handle<String> source, |
| 1675 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1676 | v8::ScriptData* pre_data, |
| 1677 | v8::Handle<String> script_data) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1678 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 1679 | i::Isolate* isolate = str->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1680 | ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>()); |
| 1681 | LOG_API(isolate, "Script::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1682 | ENTER_V8(isolate); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1683 | i::SharedFunctionInfo* raw_result = NULL; |
| 1684 | { i::HandleScope scope(isolate); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1685 | i::Handle<i::Object> name_obj; |
| 1686 | int line_offset = 0; |
| 1687 | int column_offset = 0; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1688 | bool is_shared_cross_origin = false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1689 | if (origin != NULL) { |
| 1690 | if (!origin->ResourceName().IsEmpty()) { |
| 1691 | name_obj = Utils::OpenHandle(*origin->ResourceName()); |
| 1692 | } |
| 1693 | if (!origin->ResourceLineOffset().IsEmpty()) { |
| 1694 | line_offset = static_cast<int>(origin->ResourceLineOffset()->Value()); |
| 1695 | } |
| 1696 | if (!origin->ResourceColumnOffset().IsEmpty()) { |
| 1697 | column_offset = |
| 1698 | static_cast<int>(origin->ResourceColumnOffset()->Value()); |
| 1699 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1700 | if (!origin->ResourceIsSharedCrossOrigin().IsEmpty()) { |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1701 | v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1702 | is_shared_cross_origin = |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1703 | origin->ResourceIsSharedCrossOrigin() == v8::True(v8_isolate); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1704 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1705 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1706 | EXCEPTION_PREAMBLE(isolate); |
| 1707 | i::ScriptDataImpl* pre_data_impl = |
| 1708 | static_cast<i::ScriptDataImpl*>(pre_data); |
| 1709 | // We assert that the pre-data is sane, even though we can actually |
| 1710 | // handle it if it turns out not to be in release mode. |
| 1711 | ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck()); |
| 1712 | // If the pre-data isn't sane we simply ignore it |
| 1713 | if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) { |
| 1714 | pre_data_impl = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1715 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1716 | i::Handle<i::SharedFunctionInfo> result = |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 1717 | i::Compiler::CompileScript(str, |
| 1718 | name_obj, |
| 1719 | line_offset, |
| 1720 | column_offset, |
| 1721 | is_shared_cross_origin, |
| 1722 | isolate->global_context(), |
| 1723 | NULL, |
| 1724 | pre_data_impl, |
| 1725 | Utils::OpenHandle(*script_data, true), |
| 1726 | i::NOT_NATIVES_CODE); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1727 | has_pending_exception = result.is_null(); |
| 1728 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Script>()); |
| 1729 | raw_result = *result; |
| 1730 | } |
| 1731 | i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1732 | return ToApiHandle<Script>(result); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | |
| 1736 | Local<Script> Script::New(v8::Handle<String> source, |
| 1737 | v8::Handle<Value> file_name) { |
| 1738 | ScriptOrigin origin(file_name); |
| 1739 | return New(source, &origin); |
| 1740 | } |
| 1741 | |
| 1742 | |
| 1743 | Local<Script> Script::Compile(v8::Handle<String> source, |
| 1744 | v8::ScriptOrigin* origin, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1745 | v8::ScriptData* pre_data, |
| 1746 | v8::Handle<String> script_data) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1747 | i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 1748 | i::Isolate* isolate = str->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1749 | ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>()); |
| 1750 | LOG_API(isolate, "Script::Compile"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1751 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1752 | Local<Script> generic = New(source, origin, pre_data, script_data); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1753 | if (generic.IsEmpty()) |
| 1754 | return generic; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1755 | i::Handle<i::Object> obj = Utils::OpenHandle(*generic); |
| 1756 | i::Handle<i::SharedFunctionInfo> function = |
| 1757 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1758 | i::Handle<i::JSFunction> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1759 | isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 1760 | function, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1761 | isolate->global_context()); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1762 | return ToApiHandle<Script>(result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1766 | Local<Script> Script::Compile(v8::Handle<String> source, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1767 | v8::Handle<Value> file_name, |
| 1768 | v8::Handle<String> script_data) { |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1769 | ScriptOrigin origin(file_name); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1770 | return Compile(source, &origin, 0, script_data); |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1774 | Local<Value> Script::Run() { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1775 | // If execution is terminating, Compile(script)->Run() requires this check. |
| 1776 | if (this == NULL) return Local<Value>(); |
| 1777 | i::Handle<i::HeapObject> obj = |
| 1778 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1779 | i::Isolate* isolate = obj->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1780 | ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>()); |
| 1781 | LOG_API(isolate, "Script::Run"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1782 | ENTER_V8(isolate); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1783 | i::Logger::TimerEventScope timer_scope( |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 1784 | isolate, i::Logger::TimerEventScope::v8_execute); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1785 | i::Object* raw_result = NULL; |
| 1786 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1787 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1788 | i::Handle<i::JSFunction> fun; |
| 1789 | if (obj->IsSharedFunctionInfo()) { |
| 1790 | i::Handle<i::SharedFunctionInfo> |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1791 | function_info(i::SharedFunctionInfo::cast(*obj), isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1792 | fun = isolate->factory()->NewFunctionFromSharedFunctionInfo( |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1793 | function_info, isolate->global_context()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1794 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1795 | fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1796 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1797 | EXCEPTION_PREAMBLE(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1798 | i::Handle<i::Object> receiver( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1799 | isolate->context()->global_proxy(), isolate); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 1800 | i::Handle<i::Object> result = i::Execution::Call( |
| 1801 | isolate, fun, receiver, 0, NULL, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 1802 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1803 | raw_result = *result; |
| 1804 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1805 | i::Handle<i::Object> result(raw_result, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1806 | return Utils::ToLocal(result); |
| 1807 | } |
| 1808 | |
| 1809 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1810 | static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) { |
| 1811 | i::Handle<i::Object> obj = Utils::OpenHandle(script); |
| 1812 | i::Handle<i::SharedFunctionInfo> result; |
| 1813 | if (obj->IsSharedFunctionInfo()) { |
| 1814 | result = |
| 1815 | i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); |
| 1816 | } else { |
| 1817 | result = |
| 1818 | i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()); |
| 1819 | } |
| 1820 | return result; |
| 1821 | } |
| 1822 | |
| 1823 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1824 | int Script::GetId() { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1825 | i::Handle<i::HeapObject> obj = |
| 1826 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1827 | i::Isolate* isolate = obj->GetIsolate(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1828 | ON_BAILOUT(isolate, "v8::Script::Id()", return -1); |
| 1829 | LOG_API(isolate, "Script::Id"); |
| 1830 | { |
| 1831 | i::HandleScope scope(isolate); |
| 1832 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
| 1833 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
| 1834 | return script->id()->value(); |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1839 | int Script::GetLineNumber(int code_pos) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1840 | i::Handle<i::HeapObject> obj = |
| 1841 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1842 | i::Isolate* isolate = obj->GetIsolate(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1843 | ON_BAILOUT(isolate, "v8::Script::GetLineNumber()", return -1); |
| 1844 | LOG_API(isolate, "Script::GetLineNumber"); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1845 | if (obj->IsScript()) { |
| 1846 | i::Handle<i::Script> script = i::Handle<i::Script>(i::Script::cast(*obj)); |
| 1847 | return i::GetScriptLineNumber(script, code_pos); |
| 1848 | } else { |
| 1849 | return -1; |
| 1850 | } |
| 1851 | } |
| 1852 | |
| 1853 | |
| 1854 | Handle<Value> Script::GetScriptName() { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1855 | i::Handle<i::HeapObject> obj = |
| 1856 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1857 | i::Isolate* isolate = obj->GetIsolate(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1858 | ON_BAILOUT(isolate, "v8::Script::GetName()", return Handle<String>()); |
| 1859 | LOG_API(isolate, "Script::GetName"); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1860 | if (obj->IsScript()) { |
| 1861 | i::Object* name = i::Script::cast(*obj)->name(); |
| 1862 | return Utils::ToLocal(i::Handle<i::Object>(name, isolate)); |
| 1863 | } else { |
| 1864 | return Handle<String>(); |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 1869 | void Script::SetData(v8::Handle<String> data) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 1870 | i::Handle<i::HeapObject> obj = |
| 1871 | i::Handle<i::HeapObject>::cast(Utils::OpenHandle(this)); |
| 1872 | i::Isolate* isolate = obj->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1873 | ON_BAILOUT(isolate, "v8::Script::SetData()", return); |
| 1874 | LOG_API(isolate, "Script::SetData"); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1875 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1876 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1877 | i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1878 | i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1879 | i::Handle<i::Script> script(i::Script::cast(function_info->script())); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1880 | script->set_data(*raw_data); |
| 1881 | } |
| 1882 | } |
| 1883 | |
| 1884 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1885 | // --- E x c e p t i o n s --- |
| 1886 | |
| 1887 | |
| 1888 | v8::TryCatch::TryCatch() |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1889 | : isolate_(i::Isolate::Current()), |
| 1890 | next_(isolate_->try_catch_handler_address()), |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1891 | is_verbose_(false), |
ager@chromium.org | 68e7ab7 | 2009-09-23 09:40:39 +0000 | [diff] [blame] | 1892 | can_continue_(true), |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1893 | capture_message_(true), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1894 | rethrow_(false), |
| 1895 | has_terminated_(false) { |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1896 | Reset(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1897 | isolate_->RegisterTryCatchHandler(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | |
| 1901 | v8::TryCatch::~TryCatch() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1902 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1903 | if (rethrow_) { |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1904 | v8::Isolate* isolate = reinterpret_cast<Isolate*>(isolate_); |
| 1905 | v8::HandleScope scope(isolate); |
| 1906 | 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] | 1907 | if (HasCaught() && capture_message_) { |
| 1908 | // If an exception was caught and rethrow_ is indicated, the saved |
| 1909 | // message, script, and location need to be restored to Isolate TLS |
| 1910 | // for reuse. capture_message_ needs to be disabled so that DoThrow() |
| 1911 | // does not create a new message. |
| 1912 | isolate_->thread_local_top()->rethrowing_message_ = true; |
| 1913 | isolate_->RestorePendingMessageFromTryCatch(this); |
| 1914 | } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1915 | isolate_->UnregisterTryCatchHandler(this); |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1916 | reinterpret_cast<Isolate*>(isolate_)->ThrowException(exc); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1917 | ASSERT(!isolate_->thread_local_top()->rethrowing_message_); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1918 | } else { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1919 | isolate_->UnregisterTryCatchHandler(this); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1920 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1924 | bool v8::TryCatch::HasCaught() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1925 | return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(); |
| 1926 | } |
| 1927 | |
| 1928 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 1929 | bool v8::TryCatch::CanContinue() const { |
| 1930 | return can_continue_; |
| 1931 | } |
| 1932 | |
| 1933 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1934 | bool v8::TryCatch::HasTerminated() const { |
| 1935 | return has_terminated_; |
| 1936 | } |
| 1937 | |
| 1938 | |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1939 | v8::Handle<v8::Value> v8::TryCatch::ReThrow() { |
| 1940 | if (!HasCaught()) return v8::Local<v8::Value>(); |
| 1941 | rethrow_ = true; |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 1942 | return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate_)); |
christian.plesner.hansen@gmail.com | b9ce637 | 2009-11-03 11:38:18 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1946 | v8::Local<Value> v8::TryCatch::Exception() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1947 | ASSERT(isolate_ == i::Isolate::Current()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1948 | if (HasCaught()) { |
| 1949 | // Check for out of memory exception. |
| 1950 | i::Object* exception = reinterpret_cast<i::Object*>(exception_); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1951 | return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1952 | } else { |
| 1953 | return v8::Local<Value>(); |
| 1954 | } |
| 1955 | } |
| 1956 | |
| 1957 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1958 | v8::Local<Value> v8::TryCatch::StackTrace() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1959 | ASSERT(isolate_ == i::Isolate::Current()); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1960 | if (HasCaught()) { |
| 1961 | i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_); |
| 1962 | if (!raw_obj->IsJSObject()) return v8::Local<Value>(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1963 | i::HandleScope scope(isolate_); |
| 1964 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1965 | i::Handle<i::String> name = isolate_->factory()->stack_string(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1966 | if (!i::JSReceiver::HasProperty(obj, name)) return v8::Local<Value>(); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1967 | i::Handle<i::Object> value = i::GetProperty(isolate_, obj, name); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1968 | if (value.is_null()) return v8::Local<Value>(); |
| 1969 | return v8::Utils::ToLocal(scope.CloseAndEscape(value)); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1970 | } else { |
| 1971 | return v8::Local<Value>(); |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1976 | v8::Local<v8::Message> v8::TryCatch::Message() const { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1977 | ASSERT(isolate_ == i::Isolate::Current()); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1978 | i::Object* message = reinterpret_cast<i::Object*>(message_obj_); |
| 1979 | ASSERT(message->IsJSMessageObject() || message->IsTheHole()); |
| 1980 | if (HasCaught() && !message->IsTheHole()) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1981 | return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_)); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1982 | } else { |
| 1983 | return v8::Local<v8::Message>(); |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1988 | void v8::TryCatch::Reset() { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1989 | ASSERT(isolate_ == i::Isolate::Current()); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 1990 | i::Object* the_hole = isolate_->heap()->the_hole_value(); |
| 1991 | exception_ = the_hole; |
| 1992 | message_obj_ = the_hole; |
| 1993 | message_script_ = the_hole; |
| 1994 | message_start_pos_ = 0; |
| 1995 | message_end_pos_ = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | |
| 1999 | void v8::TryCatch::SetVerbose(bool value) { |
| 2000 | is_verbose_ = value; |
| 2001 | } |
| 2002 | |
| 2003 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2004 | void v8::TryCatch::SetCaptureMessage(bool value) { |
| 2005 | capture_message_ = value; |
| 2006 | } |
| 2007 | |
| 2008 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2009 | // --- M e s s a g e --- |
| 2010 | |
| 2011 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2012 | Local<String> Message::Get() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2013 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2014 | ON_BAILOUT(isolate, "v8::Message::Get()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2015 | ENTER_V8(isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2016 | EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2017 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2018 | i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2019 | Local<String> result = Utils::ToLocal(raw_result); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2020 | return scope.Escape(result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2024 | v8::Handle<Value> Message::GetScriptResourceName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2025 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2026 | ENTER_V8(isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2027 | EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2028 | i::Handle<i::JSMessageObject> message = |
| 2029 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2030 | // Return this.script.name. |
| 2031 | i::Handle<i::JSValue> script = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2032 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(), |
| 2033 | isolate)); |
| 2034 | i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name(), |
| 2035 | isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2036 | return scope.Escape(Utils::ToLocal(resource_name)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2040 | v8::Handle<Value> Message::GetScriptData() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2041 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2042 | ENTER_V8(isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2043 | EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2044 | i::Handle<i::JSMessageObject> message = |
| 2045 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2046 | // Return this.script.data. |
| 2047 | i::Handle<i::JSValue> script = |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2048 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(), |
| 2049 | isolate)); |
| 2050 | i::Handle<i::Object> data(i::Script::cast(script->value())->data(), isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2051 | return scope.Escape(Utils::ToLocal(data)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2055 | v8::Handle<v8::StackTrace> Message::GetStackTrace() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2056 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2057 | ENTER_V8(isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2058 | EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2059 | i::Handle<i::JSMessageObject> message = |
| 2060 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2061 | i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2062 | if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); |
| 2063 | i::Handle<i::JSArray> stackTrace = |
| 2064 | i::Handle<i::JSArray>::cast(stackFramesObj); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2065 | return scope.Escape(Utils::StackTraceToLocal(stackTrace)); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2069 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 2070 | i::Handle<i::Object> recv, |
| 2071 | int argc, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2072 | i::Handle<i::Object> argv[], |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2073 | bool* has_pending_exception) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2074 | i::Isolate* isolate = i::Isolate::Current(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2075 | i::Handle<i::String> fmt_str = |
| 2076 | isolate->factory()->InternalizeUtf8String(name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2077 | i::Object* object_fun = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2078 | isolate->js_builtins_object()->GetPropertyNoExceptionThrown(*fmt_str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2079 | i::Handle<i::JSFunction> fun = |
| 2080 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun)); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 2081 | i::Handle<i::Object> value = i::Execution::Call( |
| 2082 | isolate, fun, recv, argc, argv, has_pending_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2083 | return value; |
| 2084 | } |
| 2085 | |
| 2086 | |
| 2087 | static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 2088 | i::Handle<i::Object> data, |
| 2089 | bool* has_pending_exception) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2090 | i::Handle<i::Object> argv[] = { data }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2091 | return CallV8HeapFunction(name, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2092 | i::Isolate::Current()->js_builtins_object(), |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2093 | ARRAY_SIZE(argv), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2094 | argv, |
| 2095 | has_pending_exception); |
| 2096 | } |
| 2097 | |
| 2098 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2099 | int Message::GetLineNumber() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2100 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2101 | ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2102 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2103 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2104 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2105 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2106 | i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber", |
| 2107 | Utils::OpenHandle(this), |
| 2108 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2109 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2110 | return static_cast<int>(result->Number()); |
| 2111 | } |
| 2112 | |
| 2113 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2114 | int Message::GetStartPosition() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2115 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2116 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2117 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2118 | i::Handle<i::JSMessageObject> message = |
| 2119 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 2120 | return message->start_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2124 | int Message::GetEndPosition() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2125 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2126 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2127 | i::HandleScope scope(isolate); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2128 | i::Handle<i::JSMessageObject> message = |
| 2129 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 2130 | return message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2134 | int Message::GetStartColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2135 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2136 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2137 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2138 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2139 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2140 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 2141 | "GetPositionInLine", |
| 2142 | data_obj, |
| 2143 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2144 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2145 | return static_cast<int>(start_col_obj->Number()); |
| 2146 | } |
| 2147 | |
| 2148 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2149 | int Message::GetEndColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2150 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2151 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2152 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2153 | i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2154 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2155 | i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 2156 | "GetPositionInLine", |
| 2157 | data_obj, |
| 2158 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2159 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2160 | i::Handle<i::JSMessageObject> message = |
| 2161 | i::Handle<i::JSMessageObject>::cast(data_obj); |
| 2162 | int start = message->start_position(); |
| 2163 | int end = message->end_position(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2164 | return static_cast<int>(start_col_obj->Number()) + (end - start); |
| 2165 | } |
| 2166 | |
| 2167 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2168 | bool Message::IsSharedCrossOrigin() const { |
| 2169 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2170 | ENTER_V8(isolate); |
| 2171 | i::HandleScope scope(isolate); |
| 2172 | i::Handle<i::JSMessageObject> message = |
| 2173 | i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 2174 | i::Handle<i::JSValue> script = |
| 2175 | i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script(), |
| 2176 | isolate)); |
| 2177 | return i::Script::cast(script->value())->is_shared_cross_origin(); |
| 2178 | } |
| 2179 | |
| 2180 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2181 | Local<String> Message::GetSourceLine() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2182 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2183 | ON_BAILOUT(isolate, "v8::Message::GetSourceLine()", return Local<String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2184 | ENTER_V8(isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2185 | EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2186 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2187 | i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine", |
| 2188 | Utils::OpenHandle(this), |
| 2189 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2190 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::String>()); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2191 | if (result->IsString()) { |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2192 | return scope.Escape(Utils::ToLocal(i::Handle<i::String>::cast(result))); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2193 | } else { |
| 2194 | return Local<String>(); |
| 2195 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 2199 | void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) { |
| 2200 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 2201 | ENTER_V8(i_isolate); |
| 2202 | i_isolate->PrintCurrentStackTrace(out); |
| 2203 | } |
| 2204 | |
| 2205 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2206 | // --- S t a c k T r a c e --- |
| 2207 | |
| 2208 | Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2209 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2210 | ENTER_V8(isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2211 | EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2212 | i::Handle<i::JSArray> self = Utils::OpenHandle(this); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 2213 | i::Object* raw_object = self->GetElementNoExceptionThrown(isolate, index); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2214 | i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object)); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2215 | return scope.Escape(Utils::StackFrameToLocal(obj)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | |
| 2219 | int StackTrace::GetFrameCount() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2220 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2221 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2222 | return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); |
| 2223 | } |
| 2224 | |
| 2225 | |
| 2226 | Local<Array> StackTrace::AsArray() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2227 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2228 | ENTER_V8(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2229 | return Utils::ToLocal(Utils::OpenHandle(this)); |
| 2230 | } |
| 2231 | |
| 2232 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 2233 | Local<StackTrace> StackTrace::CurrentStackTrace( |
| 2234 | Isolate* isolate, |
| 2235 | int frame_limit, |
| 2236 | StackTraceOptions options) { |
| 2237 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 2238 | ENTER_V8(i_isolate); |
| 2239 | i::Handle<i::JSArray> stackTrace = |
| 2240 | i_isolate->CaptureCurrentStackTrace(frame_limit, options); |
| 2241 | return Utils::StackTraceToLocal(stackTrace); |
| 2242 | } |
| 2243 | |
| 2244 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2245 | // --- S t a c k F r a m e --- |
| 2246 | |
| 2247 | int StackFrame::GetLineNumber() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2248 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2249 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2250 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2251 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2252 | i::Handle<i::Object> line = GetProperty(self, "lineNumber"); |
| 2253 | if (!line->IsSmi()) { |
| 2254 | return Message::kNoLineNumberInfo; |
| 2255 | } |
| 2256 | return i::Smi::cast(*line)->value(); |
| 2257 | } |
| 2258 | |
| 2259 | |
| 2260 | int StackFrame::GetColumn() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2261 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2262 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2263 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2264 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2265 | i::Handle<i::Object> column = GetProperty(self, "column"); |
| 2266 | if (!column->IsSmi()) { |
| 2267 | return Message::kNoColumnInfo; |
| 2268 | } |
| 2269 | return i::Smi::cast(*column)->value(); |
| 2270 | } |
| 2271 | |
| 2272 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 2273 | int StackFrame::GetScriptId() const { |
| 2274 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 2275 | ENTER_V8(isolate); |
| 2276 | i::HandleScope scope(isolate); |
| 2277 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2278 | i::Handle<i::Object> scriptId = GetProperty(self, "scriptId"); |
| 2279 | if (!scriptId->IsSmi()) { |
| 2280 | return Message::kNoScriptIdInfo; |
| 2281 | } |
| 2282 | return i::Smi::cast(*scriptId)->value(); |
| 2283 | } |
| 2284 | |
| 2285 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2286 | Local<String> StackFrame::GetScriptName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2287 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2288 | ENTER_V8(isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2289 | EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2290 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2291 | i::Handle<i::Object> name = GetProperty(self, "scriptName"); |
| 2292 | if (!name->IsString()) { |
| 2293 | return Local<String>(); |
| 2294 | } |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2295 | return scope.Escape(Local<String>::Cast(Utils::ToLocal(name))); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2299 | Local<String> StackFrame::GetScriptNameOrSourceURL() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2300 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2301 | ENTER_V8(isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2302 | EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2303 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2304 | i::Handle<i::Object> name = GetProperty(self, "scriptNameOrSourceURL"); |
| 2305 | if (!name->IsString()) { |
| 2306 | return Local<String>(); |
| 2307 | } |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2308 | return scope.Escape(Local<String>::Cast(Utils::ToLocal(name))); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2312 | Local<String> StackFrame::GetFunctionName() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2313 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2314 | ENTER_V8(isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2315 | EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2316 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2317 | i::Handle<i::Object> name = GetProperty(self, "functionName"); |
| 2318 | if (!name->IsString()) { |
| 2319 | return Local<String>(); |
| 2320 | } |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2321 | return scope.Escape(Local<String>::Cast(Utils::ToLocal(name))); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | |
| 2325 | bool StackFrame::IsEval() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2326 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2327 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2328 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2329 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2330 | i::Handle<i::Object> is_eval = GetProperty(self, "isEval"); |
| 2331 | return is_eval->IsTrue(); |
| 2332 | } |
| 2333 | |
| 2334 | |
| 2335 | bool StackFrame::IsConstructor() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2336 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2337 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2338 | i::HandleScope scope(isolate); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2339 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2340 | i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor"); |
| 2341 | return is_constructor->IsTrue(); |
| 2342 | } |
| 2343 | |
| 2344 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2345 | // --- J S O N --- |
| 2346 | |
| 2347 | Local<Value> JSON::Parse(Local<String> json_string) { |
| 2348 | i::Isolate* isolate = i::Isolate::Current(); |
| 2349 | EnsureInitializedForIsolate(isolate, "v8::JSON::Parse"); |
| 2350 | ENTER_V8(isolate); |
| 2351 | i::HandleScope scope(isolate); |
| 2352 | i::Handle<i::String> source = i::Handle<i::String>( |
| 2353 | FlattenGetString(Utils::OpenHandle(*json_string))); |
| 2354 | EXCEPTION_PREAMBLE(isolate); |
| 2355 | i::Handle<i::Object> result; |
| 2356 | if (source->IsSeqOneByteString()) { |
| 2357 | result = i::JsonParser<true>::Parse(source); |
| 2358 | } else { |
| 2359 | result = i::JsonParser<false>::Parse(source); |
| 2360 | } |
| 2361 | has_pending_exception = result.is_null(); |
| 2362 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
| 2363 | return Utils::ToLocal( |
| 2364 | i::Handle<i::Object>::cast(scope.CloseAndEscape(result))); |
| 2365 | } |
| 2366 | |
| 2367 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2368 | // --- D a t a --- |
| 2369 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2370 | bool Value::FullIsUndefined() const { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2371 | bool result = Utils::OpenHandle(this)->IsUndefined(); |
| 2372 | ASSERT_EQ(result, QuickIsUndefined()); |
| 2373 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2377 | bool Value::FullIsNull() const { |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 2378 | bool result = Utils::OpenHandle(this)->IsNull(); |
| 2379 | ASSERT_EQ(result, QuickIsNull()); |
| 2380 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2384 | bool Value::IsTrue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2385 | return Utils::OpenHandle(this)->IsTrue(); |
| 2386 | } |
| 2387 | |
| 2388 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2389 | bool Value::IsFalse() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2390 | return Utils::OpenHandle(this)->IsFalse(); |
| 2391 | } |
| 2392 | |
| 2393 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2394 | bool Value::IsFunction() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2395 | return Utils::OpenHandle(this)->IsJSFunction(); |
| 2396 | } |
| 2397 | |
| 2398 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2399 | bool Value::FullIsString() const { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2400 | bool result = Utils::OpenHandle(this)->IsString(); |
| 2401 | ASSERT_EQ(result, QuickIsString()); |
| 2402 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2406 | bool Value::IsSymbol() const { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2407 | return Utils::OpenHandle(this)->IsSymbol(); |
| 2408 | } |
| 2409 | |
| 2410 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2411 | bool Value::IsArray() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2412 | return Utils::OpenHandle(this)->IsJSArray(); |
| 2413 | } |
| 2414 | |
| 2415 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2416 | bool Value::IsArrayBuffer() const { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2417 | return Utils::OpenHandle(this)->IsJSArrayBuffer(); |
| 2418 | } |
| 2419 | |
| 2420 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2421 | bool Value::IsArrayBufferView() const { |
| 2422 | return Utils::OpenHandle(this)->IsJSArrayBufferView(); |
| 2423 | } |
| 2424 | |
| 2425 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2426 | bool Value::IsTypedArray() const { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2427 | return Utils::OpenHandle(this)->IsJSTypedArray(); |
| 2428 | } |
| 2429 | |
| 2430 | |
| 2431 | #define TYPED_ARRAY_LIST(F) \ |
| 2432 | F(Uint8Array, kExternalUnsignedByteArray) \ |
| 2433 | F(Int8Array, kExternalByteArray) \ |
| 2434 | F(Uint16Array, kExternalUnsignedShortArray) \ |
| 2435 | F(Int16Array, kExternalShortArray) \ |
| 2436 | F(Uint32Array, kExternalUnsignedIntArray) \ |
| 2437 | F(Int32Array, kExternalIntArray) \ |
| 2438 | F(Float32Array, kExternalFloatArray) \ |
| 2439 | F(Float64Array, kExternalDoubleArray) \ |
| 2440 | F(Uint8ClampedArray, kExternalPixelArray) |
| 2441 | |
| 2442 | |
| 2443 | #define VALUE_IS_TYPED_ARRAY(TypedArray, type_const) \ |
| 2444 | bool Value::Is##TypedArray() const { \ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2445 | i::Handle<i::Object> obj = Utils::OpenHandle(this); \ |
| 2446 | if (!obj->IsJSTypedArray()) return false; \ |
| 2447 | return i::JSTypedArray::cast(*obj)->type() == type_const; \ |
| 2448 | } |
| 2449 | |
| 2450 | TYPED_ARRAY_LIST(VALUE_IS_TYPED_ARRAY) |
| 2451 | |
| 2452 | #undef VALUE_IS_TYPED_ARRAY |
| 2453 | |
| 2454 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2455 | bool Value::IsDataView() const { |
| 2456 | return Utils::OpenHandle(this)->IsJSDataView(); |
| 2457 | } |
| 2458 | |
| 2459 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2460 | bool Value::IsObject() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2461 | return Utils::OpenHandle(this)->IsJSObject(); |
| 2462 | } |
| 2463 | |
| 2464 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2465 | bool Value::IsNumber() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2466 | return Utils::OpenHandle(this)->IsNumber(); |
| 2467 | } |
| 2468 | |
| 2469 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2470 | bool Value::IsBoolean() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2471 | return Utils::OpenHandle(this)->IsBoolean(); |
| 2472 | } |
| 2473 | |
| 2474 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2475 | bool Value::IsExternal() const { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2476 | return Utils::OpenHandle(this)->IsExternal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2480 | bool Value::IsInt32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2481 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2482 | if (obj->IsSmi()) return true; |
| 2483 | if (obj->IsNumber()) { |
hpayer@chromium.org | ea9b8ba | 2013-12-20 19:22:39 +0000 | [diff] [blame] | 2484 | return i::IsInt32Double(obj->Number()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2485 | } |
| 2486 | return false; |
| 2487 | } |
| 2488 | |
| 2489 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2490 | bool Value::IsUint32() const { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2491 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2492 | if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0; |
| 2493 | if (obj->IsNumber()) { |
| 2494 | double value = obj->Number(); |
hpayer@chromium.org | ea9b8ba | 2013-12-20 19:22:39 +0000 | [diff] [blame] | 2495 | return !i::IsMinusZero(value) && |
| 2496 | value >= 0 && |
| 2497 | value <= i::kMaxUInt32 && |
| 2498 | value == i::FastUI2D(i::FastD2UI(value)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2499 | } |
| 2500 | return false; |
| 2501 | } |
| 2502 | |
| 2503 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2504 | bool Value::IsDate() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2505 | i::Isolate* isolate = i::Isolate::Current(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2506 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2507 | return obj->HasSpecificClassOf(isolate->heap()->Date_string()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2511 | bool Value::IsStringObject() const { |
| 2512 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2513 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2514 | return obj->HasSpecificClassOf(isolate->heap()->String_string()); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2518 | bool Value::IsSymbolObject() const { |
| 2519 | // TODO(svenpanne): these and other test functions should be written such |
| 2520 | // that they do not use Isolate::Current(). |
| 2521 | i::Isolate* isolate = i::Isolate::Current(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2522 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2523 | return obj->HasSpecificClassOf(isolate->heap()->Symbol_string()); |
| 2524 | } |
| 2525 | |
| 2526 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2527 | bool Value::IsNumberObject() const { |
| 2528 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2529 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2530 | return obj->HasSpecificClassOf(isolate->heap()->Number_string()); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | |
| 2534 | static i::Object* LookupBuiltin(i::Isolate* isolate, |
| 2535 | const char* builtin_name) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2536 | i::Handle<i::String> string = |
| 2537 | isolate->factory()->InternalizeUtf8String(builtin_name); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2538 | i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2539 | return builtins->GetPropertyNoExceptionThrown(*string); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | |
| 2543 | static bool CheckConstructor(i::Isolate* isolate, |
| 2544 | i::Handle<i::JSObject> obj, |
| 2545 | const char* class_name) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2546 | i::Object* constr = obj->map()->constructor(); |
| 2547 | if (!constr->IsJSFunction()) return false; |
| 2548 | i::JSFunction* func = i::JSFunction::cast(constr); |
| 2549 | return func->shared()->native() && |
| 2550 | constr == LookupBuiltin(isolate, class_name); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | |
| 2554 | bool Value::IsNativeError() const { |
| 2555 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2556 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2557 | if (obj->IsJSObject()) { |
| 2558 | i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj)); |
| 2559 | return CheckConstructor(isolate, js_obj, "$Error") || |
| 2560 | CheckConstructor(isolate, js_obj, "$EvalError") || |
| 2561 | CheckConstructor(isolate, js_obj, "$RangeError") || |
| 2562 | CheckConstructor(isolate, js_obj, "$ReferenceError") || |
| 2563 | CheckConstructor(isolate, js_obj, "$SyntaxError") || |
| 2564 | CheckConstructor(isolate, js_obj, "$TypeError") || |
| 2565 | CheckConstructor(isolate, js_obj, "$URIError"); |
| 2566 | } else { |
| 2567 | return false; |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | |
| 2572 | bool Value::IsBooleanObject() const { |
| 2573 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2574 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2575 | return obj->HasSpecificClassOf(isolate->heap()->Boolean_string()); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2579 | bool Value::IsRegExp() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 2580 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2581 | return obj->IsJSRegExp(); |
| 2582 | } |
| 2583 | |
| 2584 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2585 | Local<String> Value::ToString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2586 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2587 | i::Handle<i::Object> str; |
| 2588 | if (obj->IsString()) { |
| 2589 | str = obj; |
| 2590 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2591 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2592 | LOG_API(isolate, "ToString"); |
| 2593 | ENTER_V8(isolate); |
| 2594 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2595 | str = i::Execution::ToString(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2596 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2597 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2598 | return ToApiHandle<String>(str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2602 | Local<String> Value::ToDetailString() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2603 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2604 | i::Handle<i::Object> str; |
| 2605 | if (obj->IsString()) { |
| 2606 | str = obj; |
| 2607 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2608 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2609 | LOG_API(isolate, "ToDetailString"); |
| 2610 | ENTER_V8(isolate); |
| 2611 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2612 | str = i::Execution::ToDetailString(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2613 | EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2614 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2615 | return ToApiHandle<String>(str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2619 | Local<v8::Object> Value::ToObject() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2620 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2621 | i::Handle<i::Object> val; |
| 2622 | if (obj->IsJSObject()) { |
| 2623 | val = obj; |
| 2624 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2625 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2626 | LOG_API(isolate, "ToObject"); |
| 2627 | ENTER_V8(isolate); |
| 2628 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2629 | val = i::Execution::ToObject(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2630 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2631 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2632 | return ToApiHandle<Object>(val); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2633 | } |
| 2634 | |
| 2635 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2636 | Local<Boolean> Value::ToBoolean() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2637 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2638 | if (obj->IsBoolean()) { |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2639 | return ToApiHandle<Boolean>(obj); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2640 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2641 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2642 | LOG_API(isolate, "ToBoolean"); |
| 2643 | ENTER_V8(isolate); |
svenpanne@chromium.org | 9faefa4 | 2013-03-08 13:13:16 +0000 | [diff] [blame] | 2644 | i::Handle<i::Object> val = |
| 2645 | isolate->factory()->ToBoolean(obj->BooleanValue()); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2646 | return ToApiHandle<Boolean>(val); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2647 | } |
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<Number> Value::ToNumber() 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> num; |
| 2654 | if (obj->IsNumber()) { |
| 2655 | num = 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, "ToNumber"); |
| 2659 | ENTER_V8(isolate); |
| 2660 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2661 | num = i::Execution::ToNumber(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2662 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Number>()); |
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<Number>(num); |
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<Integer> Value::ToInteger() 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> num; |
| 2671 | if (obj->IsSmi()) { |
| 2672 | num = 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, "ToInteger"); |
| 2676 | ENTER_V8(isolate); |
| 2677 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2678 | num = i::Execution::ToInteger(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2679 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>()); |
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<Integer>(num); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 2685 | void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2686 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2687 | ApiCheck(isolate != NULL && isolate->IsInitialized() && !isolate->IsDead(), |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2688 | "v8::internal::Internals::CheckInitialized()", |
| 2689 | "Isolate is not initialized or V8 has died"); |
| 2690 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2691 | |
| 2692 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2693 | void External::CheckCast(v8::Value* that) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2694 | ApiCheck(Utils::OpenHandle(that)->IsExternal(), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2695 | "v8::External::Cast()", |
| 2696 | "Could not convert to external"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2700 | void v8::Object::CheckCast(Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2701 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2702 | ApiCheck(obj->IsJSObject(), |
| 2703 | "v8::Object::Cast()", |
| 2704 | "Could not convert to object"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2708 | void v8::Function::CheckCast(Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2709 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2710 | ApiCheck(obj->IsJSFunction(), |
| 2711 | "v8::Function::Cast()", |
| 2712 | "Could not convert to function"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2716 | void v8::String::CheckCast(v8::Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2717 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2718 | ApiCheck(obj->IsString(), |
| 2719 | "v8::String::Cast()", |
| 2720 | "Could not convert to string"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2724 | void v8::Symbol::CheckCast(v8::Value* that) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2725 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2726 | ApiCheck(obj->IsSymbol(), |
| 2727 | "v8::Symbol::Cast()", |
| 2728 | "Could not convert to symbol"); |
| 2729 | } |
| 2730 | |
| 2731 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2732 | void v8::Number::CheckCast(v8::Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2733 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2734 | ApiCheck(obj->IsNumber(), |
| 2735 | "v8::Number::Cast()", |
| 2736 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2740 | void v8::Integer::CheckCast(v8::Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2741 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2742 | ApiCheck(obj->IsNumber(), |
| 2743 | "v8::Integer::Cast()", |
| 2744 | "Could not convert to number"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2745 | } |
| 2746 | |
| 2747 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2748 | void v8::Array::CheckCast(Value* that) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2749 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2750 | ApiCheck(obj->IsJSArray(), |
| 2751 | "v8::Array::Cast()", |
| 2752 | "Could not convert to array"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2756 | void v8::ArrayBuffer::CheckCast(Value* that) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2757 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2758 | ApiCheck(obj->IsJSArrayBuffer(), |
| 2759 | "v8::ArrayBuffer::Cast()", |
| 2760 | "Could not convert to ArrayBuffer"); |
| 2761 | } |
| 2762 | |
| 2763 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2764 | void v8::ArrayBufferView::CheckCast(Value* that) { |
| 2765 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2766 | ApiCheck(obj->IsJSArrayBufferView(), |
| 2767 | "v8::ArrayBufferView::Cast()", |
| 2768 | "Could not convert to ArrayBufferView"); |
| 2769 | } |
| 2770 | |
| 2771 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2772 | void v8::TypedArray::CheckCast(Value* that) { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2773 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2774 | ApiCheck(obj->IsJSTypedArray(), |
| 2775 | "v8::TypedArray::Cast()", |
| 2776 | "Could not convert to TypedArray"); |
| 2777 | } |
| 2778 | |
| 2779 | |
| 2780 | #define CHECK_TYPED_ARRAY_CAST(ApiClass, typeConst) \ |
| 2781 | void v8::ApiClass::CheckCast(Value* that) { \ |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2782 | i::Handle<i::Object> obj = Utils::OpenHandle(that); \ |
| 2783 | ApiCheck(obj->IsJSTypedArray() && \ |
| 2784 | i::JSTypedArray::cast(*obj)->type() == typeConst, \ |
| 2785 | "v8::" #ApiClass "::Cast()", \ |
| 2786 | "Could not convert to " #ApiClass); \ |
| 2787 | } |
| 2788 | |
| 2789 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2790 | TYPED_ARRAY_LIST(CHECK_TYPED_ARRAY_CAST) |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2791 | |
| 2792 | #undef CHECK_TYPED_ARRAY_CAST |
| 2793 | |
| 2794 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2795 | void v8::DataView::CheckCast(Value* that) { |
| 2796 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2797 | ApiCheck(obj->IsJSDataView(), |
| 2798 | "v8::DataView::Cast()", |
| 2799 | "Could not convert to DataView"); |
| 2800 | } |
| 2801 | |
| 2802 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2803 | void v8::Date::CheckCast(v8::Value* that) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2804 | i::Isolate* isolate = i::Isolate::Current(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2805 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2806 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_string()), |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2807 | "v8::Date::Cast()", |
| 2808 | "Could not convert to date"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2812 | void v8::StringObject::CheckCast(v8::Value* that) { |
| 2813 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2814 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2815 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->String_string()), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2816 | "v8::StringObject::Cast()", |
| 2817 | "Could not convert to StringObject"); |
| 2818 | } |
| 2819 | |
| 2820 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2821 | void v8::SymbolObject::CheckCast(v8::Value* that) { |
| 2822 | i::Isolate* isolate = i::Isolate::Current(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2823 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2824 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Symbol_string()), |
| 2825 | "v8::SymbolObject::Cast()", |
| 2826 | "Could not convert to SymbolObject"); |
| 2827 | } |
| 2828 | |
| 2829 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2830 | void v8::NumberObject::CheckCast(v8::Value* that) { |
| 2831 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2832 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2833 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Number_string()), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2834 | "v8::NumberObject::Cast()", |
| 2835 | "Could not convert to NumberObject"); |
| 2836 | } |
| 2837 | |
| 2838 | |
| 2839 | void v8::BooleanObject::CheckCast(v8::Value* that) { |
| 2840 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2841 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2842 | ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Boolean_string()), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2843 | "v8::BooleanObject::Cast()", |
| 2844 | "Could not convert to BooleanObject"); |
| 2845 | } |
| 2846 | |
| 2847 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2848 | void v8::RegExp::CheckCast(v8::Value* that) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 2849 | i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2850 | ApiCheck(obj->IsJSRegExp(), |
| 2851 | "v8::RegExp::Cast()", |
| 2852 | "Could not convert to regular expression"); |
| 2853 | } |
| 2854 | |
| 2855 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2856 | bool Value::BooleanValue() const { |
svenpanne@chromium.org | 9faefa4 | 2013-03-08 13:13:16 +0000 | [diff] [blame] | 2857 | return Utils::OpenHandle(this)->BooleanValue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2861 | double Value::NumberValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2862 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2863 | i::Handle<i::Object> num; |
| 2864 | if (obj->IsNumber()) { |
| 2865 | num = obj; |
| 2866 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2867 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2868 | LOG_API(isolate, "NumberValue"); |
| 2869 | ENTER_V8(isolate); |
| 2870 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2871 | num = i::Execution::ToNumber(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2872 | EXCEPTION_BAILOUT_CHECK(isolate, i::OS::nan_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2873 | } |
| 2874 | return num->Number(); |
| 2875 | } |
| 2876 | |
| 2877 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2878 | int64_t Value::IntegerValue() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2879 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2880 | i::Handle<i::Object> num; |
| 2881 | if (obj->IsNumber()) { |
| 2882 | num = obj; |
| 2883 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2884 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2885 | LOG_API(isolate, "IntegerValue"); |
| 2886 | ENTER_V8(isolate); |
| 2887 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2888 | num = i::Execution::ToInteger(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2889 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2890 | } |
| 2891 | if (num->IsSmi()) { |
| 2892 | return i::Smi::cast(*num)->value(); |
| 2893 | } else { |
| 2894 | return static_cast<int64_t>(num->Number()); |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2899 | Local<Int32> Value::ToInt32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2900 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2901 | i::Handle<i::Object> num; |
| 2902 | if (obj->IsSmi()) { |
| 2903 | num = obj; |
| 2904 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2905 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2906 | LOG_API(isolate, "ToInt32"); |
| 2907 | ENTER_V8(isolate); |
| 2908 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2909 | num = i::Execution::ToInt32(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2910 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Int32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2911 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2912 | return ToApiHandle<Int32>(num); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2916 | Local<Uint32> Value::ToUint32() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2917 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2918 | i::Handle<i::Object> num; |
| 2919 | if (obj->IsSmi()) { |
| 2920 | num = obj; |
| 2921 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2922 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2923 | LOG_API(isolate, "ToUInt32"); |
| 2924 | ENTER_V8(isolate); |
| 2925 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2926 | num = i::Execution::ToUint32(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2927 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2928 | } |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2929 | return ToApiHandle<Uint32>(num); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2933 | Local<Uint32> Value::ToArrayIndex() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2934 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2935 | if (obj->IsSmi()) { |
| 2936 | if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj); |
| 2937 | return Local<Uint32>(); |
| 2938 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2939 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2940 | LOG_API(isolate, "ToArrayIndex"); |
| 2941 | ENTER_V8(isolate); |
| 2942 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2943 | i::Handle<i::Object> string_obj = |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2944 | i::Execution::ToString(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2945 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2946 | i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj); |
| 2947 | uint32_t index; |
| 2948 | if (str->AsArrayIndex(&index)) { |
| 2949 | i::Handle<i::Object> value; |
| 2950 | if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 2951 | value = i::Handle<i::Object>(i::Smi::FromInt(index), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2952 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2953 | value = isolate->factory()->NewNumber(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2954 | } |
| 2955 | return Utils::Uint32ToLocal(value); |
| 2956 | } |
| 2957 | return Local<Uint32>(); |
| 2958 | } |
| 2959 | |
| 2960 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2961 | int32_t Value::Int32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2962 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2963 | if (obj->IsSmi()) { |
| 2964 | return i::Smi::cast(*obj)->value(); |
| 2965 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2966 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2967 | LOG_API(isolate, "Int32Value (slow)"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2968 | ENTER_V8(isolate); |
| 2969 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2970 | i::Handle<i::Object> num = |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 2971 | i::Execution::ToInt32(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2972 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2973 | if (num->IsSmi()) { |
| 2974 | return i::Smi::cast(*num)->value(); |
| 2975 | } else { |
| 2976 | return static_cast<int32_t>(num->Number()); |
| 2977 | } |
| 2978 | } |
| 2979 | } |
| 2980 | |
| 2981 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2982 | bool Value::Equals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2983 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 2984 | if (EmptyCheck("v8::Value::Equals()", this) || |
| 2985 | EmptyCheck("v8::Value::Equals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2986 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 2987 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2988 | LOG_API(isolate, "Equals"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2989 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2990 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2991 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2992 | // If both obj and other are JSObjects, we'd better compare by identity |
| 2993 | // immediately when going into JS builtin. The reason is Invoke |
| 2994 | // would overwrite global object receiver with global proxy. |
| 2995 | if (obj->IsJSObject() && other->IsJSObject()) { |
| 2996 | return *obj == *other; |
| 2997 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2998 | i::Handle<i::Object> args[] = { other }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2999 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3000 | i::Handle<i::Object> result = |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3001 | CallV8HeapFunction("EQUALS", obj, ARRAY_SIZE(args), args, |
| 3002 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3003 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3004 | return *result == i::Smi::FromInt(i::EQUAL); |
| 3005 | } |
| 3006 | |
| 3007 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3008 | bool Value::StrictEquals(Handle<Value> that) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3009 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 3010 | if (EmptyCheck("v8::Value::StrictEquals()", this) || |
| 3011 | EmptyCheck("v8::Value::StrictEquals()", that)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3012 | return false; |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 3013 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3014 | LOG_API(isolate, "StrictEquals"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3015 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3016 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
| 3017 | // Must check HeapNumber first, since NaN !== NaN. |
| 3018 | if (obj->IsHeapNumber()) { |
| 3019 | if (!other->IsNumber()) return false; |
| 3020 | double x = obj->Number(); |
| 3021 | double y = other->Number(); |
| 3022 | // 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] | 3023 | return x == y && !std::isnan(x) && !std::isnan(y); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3024 | } else if (*obj == *other) { // Also covers Booleans. |
| 3025 | return true; |
| 3026 | } else if (obj->IsSmi()) { |
| 3027 | return other->IsNumber() && obj->Number() == other->Number(); |
| 3028 | } else if (obj->IsString()) { |
| 3029 | return other->IsString() && |
| 3030 | i::String::cast(*obj)->Equals(i::String::cast(*other)); |
| 3031 | } else if (obj->IsUndefined() || obj->IsUndetectableObject()) { |
| 3032 | return other->IsUndefined() || other->IsUndetectableObject(); |
| 3033 | } else { |
| 3034 | return false; |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 3039 | bool Value::SameValue(Handle<Value> that) const { |
| 3040 | i::Isolate* isolate = i::Isolate::Current(); |
| 3041 | if (EmptyCheck("v8::Value::SameValue()", this) || |
| 3042 | EmptyCheck("v8::Value::SameValue()", that)) { |
| 3043 | return false; |
| 3044 | } |
| 3045 | LOG_API(isolate, "SameValue"); |
| 3046 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3047 | i::Handle<i::Object> other = Utils::OpenHandle(*that); |
| 3048 | return obj->SameValue(*other); |
| 3049 | } |
| 3050 | |
| 3051 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3052 | uint32_t Value::Uint32Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3053 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 3054 | if (obj->IsSmi()) { |
| 3055 | return i::Smi::cast(*obj)->value(); |
| 3056 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3057 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3058 | LOG_API(isolate, "Uint32Value"); |
| 3059 | ENTER_V8(isolate); |
| 3060 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3061 | i::Handle<i::Object> num = |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3062 | i::Execution::ToUint32(isolate, obj, &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3063 | EXCEPTION_BAILOUT_CHECK(isolate, 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3064 | if (num->IsSmi()) { |
| 3065 | return i::Smi::cast(*num)->value(); |
| 3066 | } else { |
| 3067 | return static_cast<uint32_t>(num->Number()); |
| 3068 | } |
| 3069 | } |
| 3070 | } |
| 3071 | |
| 3072 | |
| 3073 | 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] | 3074 | v8::PropertyAttribute attribs) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3075 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3076 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3077 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3078 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3079 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 3080 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3081 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3082 | EXCEPTION_PREAMBLE(isolate); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 3083 | i::Handle<i::Object> obj = i::Runtime::SetObjectProperty( |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 3084 | isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3085 | self, |
| 3086 | key_obj, |
| 3087 | value_obj, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3088 | static_cast<PropertyAttributes>(attribs), |
| 3089 | i::kNonStrictMode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3090 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3091 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3092 | return true; |
| 3093 | } |
| 3094 | |
| 3095 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3096 | bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3097 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3098 | ON_BAILOUT(isolate, "v8::Object::Set()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3099 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3100 | i::HandleScope scope(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3101 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3102 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3103 | EXCEPTION_PREAMBLE(isolate); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3104 | i::Handle<i::Object> obj = i::JSObject::SetElement( |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3105 | self, |
| 3106 | index, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3107 | value_obj, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 3108 | NONE, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3109 | i::kNonStrictMode); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3110 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3111 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3112 | return true; |
| 3113 | } |
| 3114 | |
| 3115 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3116 | bool v8::Object::ForceSet(v8::Handle<Value> key, |
| 3117 | v8::Handle<Value> value, |
| 3118 | v8::PropertyAttribute attribs) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3119 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3120 | ON_BAILOUT(isolate, "v8::Object::ForceSet()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3121 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3122 | i::HandleScope scope(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3123 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3124 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3125 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3126 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3127 | i::Handle<i::Object> obj = i::ForceSetProperty( |
| 3128 | self, |
| 3129 | key_obj, |
| 3130 | value_obj, |
| 3131 | static_cast<PropertyAttributes>(attribs)); |
| 3132 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3133 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3134 | return true; |
| 3135 | } |
| 3136 | |
| 3137 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3138 | bool v8::Object::SetPrivate(v8::Handle<Private> key, v8::Handle<Value> value) { |
| 3139 | return Set(v8::Handle<Value>(reinterpret_cast<Value*>(*key)), |
| 3140 | value, DontEnum); |
| 3141 | } |
| 3142 | |
| 3143 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3144 | bool v8::Object::ForceDelete(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3145 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3146 | ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3147 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3148 | i::HandleScope scope(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3149 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3150 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3151 | |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 3152 | // When deleting a property on the global object using ForceDelete |
| 3153 | // deoptimize all functions as optimized code does not check for the hole |
| 3154 | // value with DontDelete properties. We have to deoptimize all contexts |
| 3155 | // because of possible cross-context inlined functions. |
| 3156 | if (self->IsJSGlobalProxy() || self->IsGlobalObject()) { |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 3157 | i::Deoptimizer::DeoptimizeAll(isolate); |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 3158 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3159 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3160 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3161 | i::Handle<i::Object> obj = i::ForceDeleteProperty(self, key_obj); |
| 3162 | has_pending_exception = obj.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3163 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3164 | return obj->IsTrue(); |
| 3165 | } |
| 3166 | |
| 3167 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3168 | Local<Value> v8::Object::Get(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3169 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3170 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3171 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3172 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
| 3173 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3174 | EXCEPTION_PREAMBLE(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3175 | i::Handle<i::Object> result = i::GetProperty(isolate, self, key_obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3176 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3177 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3178 | return Utils::ToLocal(result); |
| 3179 | } |
| 3180 | |
| 3181 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3182 | Local<Value> v8::Object::Get(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3183 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3184 | ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3185 | ENTER_V8(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3186 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3187 | EXCEPTION_PREAMBLE(isolate); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3188 | i::Handle<i::Object> result = i::Object::GetElement(isolate, self, index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3189 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3190 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3191 | return Utils::ToLocal(result); |
| 3192 | } |
| 3193 | |
| 3194 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3195 | Local<Value> v8::Object::GetPrivate(v8::Handle<Private> key) { |
| 3196 | return Get(v8::Handle<Value>(reinterpret_cast<Value*>(*key))); |
| 3197 | } |
| 3198 | |
| 3199 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3200 | PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) { |
| 3201 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3202 | ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()", |
| 3203 | return static_cast<PropertyAttribute>(NONE)); |
| 3204 | ENTER_V8(isolate); |
| 3205 | i::HandleScope scope(isolate); |
| 3206 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3207 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3208 | if (!key_obj->IsName()) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3209 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3210 | key_obj = i::Execution::ToString(isolate, key_obj, &has_pending_exception); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3211 | EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE)); |
| 3212 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3213 | i::Handle<i::Name> key_name = i::Handle<i::Name>::cast(key_obj); |
| 3214 | PropertyAttributes result = self->GetPropertyAttribute(*key_name); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 3215 | if (result == ABSENT) return static_cast<PropertyAttribute>(NONE); |
| 3216 | return static_cast<PropertyAttribute>(result); |
| 3217 | } |
| 3218 | |
| 3219 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3220 | Local<Value> v8::Object::GetPrototype() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3221 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3222 | ON_BAILOUT(isolate, "v8::Object::GetPrototype()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3223 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3224 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3225 | i::Handle<i::Object> self = Utils::OpenHandle(this); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3226 | i::Handle<i::Object> result(self->GetPrototype(isolate), isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3227 | return Utils::ToLocal(result); |
| 3228 | } |
| 3229 | |
| 3230 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3231 | bool v8::Object::SetPrototype(Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3232 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3233 | ON_BAILOUT(isolate, "v8::Object::SetPrototype()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3234 | ENTER_V8(isolate); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3235 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3236 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3237 | // We do not allow exceptions thrown while setting the prototype |
| 3238 | // to propagate outside. |
| 3239 | TryCatch try_catch; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3240 | EXCEPTION_PREAMBLE(isolate); |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 3241 | i::Handle<i::Object> result = i::JSObject::SetPrototype(self, value_obj); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3242 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3243 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3244 | return true; |
| 3245 | } |
| 3246 | |
| 3247 | |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 3248 | Local<Object> v8::Object::FindInstanceInPrototypeChain( |
| 3249 | v8::Handle<FunctionTemplate> tmpl) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3250 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3251 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3252 | "v8::Object::FindInstanceInPrototypeChain()", |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 3253 | return Local<v8::Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3254 | ENTER_V8(isolate); |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 3255 | i::JSObject* object = *Utils::OpenHandle(this); |
| 3256 | i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3257 | while (!tmpl_info->IsTemplateFor(object)) { |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 3258 | i::Object* prototype = object->GetPrototype(); |
| 3259 | if (!prototype->IsJSObject()) return Local<Object>(); |
| 3260 | object = i::JSObject::cast(prototype); |
| 3261 | } |
| 3262 | return Utils::ToLocal(i::Handle<i::JSObject>(object)); |
| 3263 | } |
| 3264 | |
| 3265 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3266 | Local<Array> v8::Object::GetPropertyNames() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3267 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3268 | ON_BAILOUT(isolate, "v8::Object::GetPropertyNames()", |
| 3269 | return Local<v8::Array>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3270 | ENTER_V8(isolate); |
| 3271 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3272 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3273 | bool threw = false; |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3274 | i::Handle<i::FixedArray> value = |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3275 | i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS, &threw); |
| 3276 | if (threw) return Local<v8::Array>(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3277 | // Because we use caching to speed up enumeration it is important |
| 3278 | // to never change the result of the basic enumeration function so |
| 3279 | // we clone the result. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3280 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 3281 | i::Handle<i::JSArray> result = |
| 3282 | isolate->factory()->NewJSArrayWithElements(elms); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3283 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3284 | } |
| 3285 | |
| 3286 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3287 | Local<Array> v8::Object::GetOwnPropertyNames() { |
| 3288 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3289 | ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyNames()", |
| 3290 | return Local<v8::Array>()); |
| 3291 | ENTER_V8(isolate); |
| 3292 | i::HandleScope scope(isolate); |
| 3293 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3294 | bool threw = false; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3295 | i::Handle<i::FixedArray> value = |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3296 | i::GetKeysInFixedArrayFor(self, i::LOCAL_ONLY, &threw); |
| 3297 | if (threw) return Local<v8::Array>(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3298 | // Because we use caching to speed up enumeration it is important |
| 3299 | // to never change the result of the basic enumeration function so |
| 3300 | // we clone the result. |
| 3301 | i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
| 3302 | i::Handle<i::JSArray> result = |
| 3303 | isolate->factory()->NewJSArrayWithElements(elms); |
| 3304 | return Utils::ToLocal(scope.CloseAndEscape(result)); |
| 3305 | } |
| 3306 | |
| 3307 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3308 | Local<String> v8::Object::ObjectProtoToString() { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3309 | i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3310 | Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); |
| 3311 | ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3312 | return Local<v8::String>()); |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3313 | ENTER_V8(i_isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3314 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3315 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3316 | i::Handle<i::Object> name(self->class_name(), i_isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3317 | |
| 3318 | // Native implementation of Object.prototype.toString (v8natives.js): |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3319 | // var c = %_ClassOf(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3320 | // if (c === 'Arguments') c = 'Object'; |
| 3321 | // return "[object " + c + "]"; |
| 3322 | |
| 3323 | if (!name->IsString()) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3324 | return v8::String::NewFromUtf8(isolate, "[object ]"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3325 | } else { |
| 3326 | 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] | 3327 | if (class_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Arguments"))) { |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3328 | return v8::String::NewFromUtf8(isolate, "[object Object]"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3329 | } else { |
| 3330 | const char* prefix = "[object "; |
| 3331 | Local<String> str = Utils::ToLocal(class_name); |
| 3332 | const char* postfix = "]"; |
| 3333 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3334 | int prefix_len = i::StrLength(prefix); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3335 | int str_len = str->Utf8Length(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3336 | int postfix_len = i::StrLength(postfix); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3337 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3338 | int buf_len = prefix_len + str_len + postfix_len; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3339 | i::ScopedVector<char> buf(buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3340 | |
| 3341 | // Write prefix. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3342 | char* ptr = buf.start(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3343 | i::OS::MemCopy(ptr, prefix, prefix_len * v8::internal::kCharSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3344 | ptr += prefix_len; |
| 3345 | |
| 3346 | // Write real content. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3347 | str->WriteUtf8(ptr, str_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3348 | ptr += str_len; |
| 3349 | |
| 3350 | // Write postfix. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3351 | i::OS::MemCopy(ptr, postfix, postfix_len * v8::internal::kCharSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3352 | |
| 3353 | // Copy the buffer into a heap-allocated string and return it. |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 3354 | Local<String> result = v8::String::NewFromUtf8( |
| 3355 | isolate, buf.start(), String::kNormalString, buf_len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3356 | return result; |
| 3357 | } |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 3362 | Local<Value> v8::Object::GetConstructor() { |
| 3363 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3364 | ON_BAILOUT(isolate, "v8::Object::GetConstructor()", |
| 3365 | return Local<v8::Function>()); |
| 3366 | ENTER_V8(isolate); |
| 3367 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 3368 | i::Handle<i::Object> constructor(self->GetConstructor(), isolate); |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 3369 | return Utils::ToLocal(constructor); |
| 3370 | } |
| 3371 | |
| 3372 | |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 3373 | Local<String> v8::Object::GetConstructorName() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3374 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3375 | ON_BAILOUT(isolate, "v8::Object::GetConstructorName()", |
| 3376 | return Local<v8::String>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3377 | ENTER_V8(isolate); |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 3378 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3379 | i::Handle<i::String> name(self->constructor_name()); |
| 3380 | return Utils::ToLocal(name); |
| 3381 | } |
| 3382 | |
| 3383 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3384 | bool v8::Object::Delete(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3385 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3386 | ON_BAILOUT(isolate, "v8::Object::Delete()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3387 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3388 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3389 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3390 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3391 | EXCEPTION_PREAMBLE(isolate); |
| 3392 | i::Handle<i::Object> obj = i::DeleteProperty(self, key_obj); |
| 3393 | has_pending_exception = obj.is_null(); |
| 3394 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
| 3395 | return obj->IsTrue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3399 | bool v8::Object::DeletePrivate(v8::Handle<Private> key) { |
| 3400 | return Delete(v8::Handle<Value>(reinterpret_cast<Value*>(*key))); |
| 3401 | } |
| 3402 | |
| 3403 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3404 | bool v8::Object::Has(v8::Handle<Value> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3405 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3406 | ON_BAILOUT(isolate, "v8::Object::Has()", return false); |
| 3407 | ENTER_V8(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3408 | i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); |
| 3409 | i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
| 3410 | EXCEPTION_PREAMBLE(isolate); |
| 3411 | i::Handle<i::Object> obj = i::HasProperty(self, key_obj); |
| 3412 | has_pending_exception = obj.is_null(); |
| 3413 | EXCEPTION_BAILOUT_CHECK(isolate, false); |
| 3414 | return obj->IsTrue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3418 | bool v8::Object::HasPrivate(v8::Handle<Private> key) { |
| 3419 | return Has(v8::Handle<Value>(reinterpret_cast<Value*>(*key))); |
| 3420 | } |
| 3421 | |
| 3422 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3423 | bool v8::Object::Delete(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3424 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3425 | ON_BAILOUT(isolate, "v8::Object::DeleteProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3426 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3427 | ENTER_V8(isolate); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3428 | HandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3429 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 3430 | return i::JSReceiver::DeleteElement(self, index)->IsTrue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | |
| 3434 | bool v8::Object::Has(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3435 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3436 | ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3437 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3438 | return i::JSReceiver::HasElement(self, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3442 | template<typename Setter, typename Getter, typename Data> |
| 3443 | static inline bool ObjectSetAccessor(Object* obj, |
| 3444 | Handle<String> name, |
| 3445 | Setter getter, |
| 3446 | Getter setter, |
| 3447 | Data data, |
| 3448 | AccessControl settings, |
| 3449 | PropertyAttribute attributes) { |
| 3450 | i::Isolate* isolate = Utils::OpenHandle(obj)->GetIsolate(); |
| 3451 | ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false); |
| 3452 | ENTER_V8(isolate); |
| 3453 | i::HandleScope scope(isolate); |
| 3454 | v8::Handle<AccessorSignature> signature; |
| 3455 | i::Handle<i::AccessorInfo> info = MakeAccessorInfo( |
| 3456 | name, getter, setter, data, settings, attributes, signature); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3457 | if (info.is_null()) return false; |
| 3458 | bool fast = Utils::OpenHandle(obj)->HasFastProperties(); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 3459 | i::Handle<i::Object> result = |
| 3460 | i::JSObject::SetAccessor(Utils::OpenHandle(obj), info); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3461 | if (result.is_null() || result->IsUndefined()) return false; |
| 3462 | if (fast) i::JSObject::TransformToFastProperties(Utils::OpenHandle(obj), 0); |
| 3463 | return true; |
| 3464 | } |
| 3465 | |
| 3466 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3467 | bool Object::SetAccessor(Handle<String> name, |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3468 | AccessorGetterCallback getter, |
| 3469 | AccessorSetterCallback setter, |
| 3470 | v8::Handle<Value> data, |
| 3471 | AccessControl settings, |
| 3472 | PropertyAttribute attributes) { |
| 3473 | return ObjectSetAccessor( |
| 3474 | this, name, getter, setter, data, settings, attributes); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 3478 | bool Object::SetDeclaredAccessor(Local<String> name, |
| 3479 | Local<DeclaredAccessorDescriptor> descriptor, |
| 3480 | PropertyAttribute attributes, |
| 3481 | AccessControl settings) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 3482 | void* null = NULL; |
| 3483 | return ObjectSetAccessor( |
| 3484 | this, name, descriptor, null, null, settings, attributes); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3488 | bool v8::Object::HasOwnProperty(Handle<String> key) { |
| 3489 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3490 | ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()", |
| 3491 | return false); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3492 | return i::JSReceiver::HasLocalProperty( |
| 3493 | Utils::OpenHandle(this), Utils::OpenHandle(*key)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3497 | bool v8::Object::HasRealNamedProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3498 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3499 | ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3500 | return false); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3501 | return i::JSObject::HasRealNamedProperty(Utils::OpenHandle(this), |
| 3502 | Utils::OpenHandle(*key)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | |
| 3506 | bool v8::Object::HasRealIndexedProperty(uint32_t index) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 3507 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3508 | ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3509 | return false); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3510 | return i::JSObject::HasRealElementProperty(Utils::OpenHandle(this), index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | |
| 3514 | bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3515 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3516 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3517 | "v8::Object::HasRealNamedCallbackProperty()", |
| 3518 | return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3519 | ENTER_V8(isolate); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 3520 | return i::JSObject::HasRealNamedCallbackProperty(Utils::OpenHandle(this), |
| 3521 | Utils::OpenHandle(*key)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | |
| 3525 | bool v8::Object::HasNamedLookupInterceptor() { |
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::HasNamedLookupInterceptor()", |
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)->HasNamedInterceptor(); |
| 3530 | } |
| 3531 | |
| 3532 | |
| 3533 | bool v8::Object::HasIndexedLookupInterceptor() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3534 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3535 | ON_BAILOUT(isolate, "v8::Object::HasIndexedLookupInterceptor()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3536 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3537 | return Utils::OpenHandle(this)->HasIndexedInterceptor(); |
| 3538 | } |
| 3539 | |
| 3540 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3541 | static Local<Value> GetPropertyByLookup(i::Isolate* isolate, |
| 3542 | i::Handle<i::JSObject> receiver, |
| 3543 | i::Handle<i::String> name, |
| 3544 | i::LookupResult* lookup) { |
| 3545 | if (!lookup->IsProperty()) { |
| 3546 | // No real property was found. |
| 3547 | return Local<Value>(); |
| 3548 | } |
| 3549 | |
| 3550 | // If the property being looked up is a callback, it can throw |
| 3551 | // an exception. |
| 3552 | EXCEPTION_PREAMBLE(isolate); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3553 | PropertyAttributes ignored; |
| 3554 | i::Handle<i::Object> result = |
| 3555 | i::Object::GetProperty(receiver, receiver, lookup, name, |
| 3556 | &ignored); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3557 | has_pending_exception = result.is_null(); |
| 3558 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3559 | |
| 3560 | return Utils::ToLocal(result); |
| 3561 | } |
| 3562 | |
| 3563 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3564 | Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3565 | Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3566 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3567 | ON_BAILOUT(isolate, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3568 | "v8::Object::GetRealNamedPropertyInPrototypeChain()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3569 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3570 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3571 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3572 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3573 | i::LookupResult lookup(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3574 | self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3575 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3579 | Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3580 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3581 | ON_BAILOUT(isolate, "v8::Object::GetRealNamedProperty()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3582 | return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3583 | ENTER_V8(isolate); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3584 | i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
| 3585 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3586 | i::LookupResult lookup(isolate); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3587 | self_obj->LookupRealNamedProperty(*key_obj, &lookup); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3588 | return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
sgjesse@chromium.org | 98aff2f | 2009-09-30 08:27:10 +0000 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3592 | // Turns on access checks by copying the map and setting the check flag. |
| 3593 | // Because the object gets a new map, existing inline cache caching |
| 3594 | // the old map of this object will fail. |
| 3595 | void v8::Object::TurnOnAccessCheck() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3596 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3597 | ON_BAILOUT(isolate, "v8::Object::TurnOnAccessCheck()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3598 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3599 | i::HandleScope scope(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3600 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3601 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3602 | // When turning on access checks for a global object deoptimize all functions |
| 3603 | // as optimized code does not always handle access checks. |
| 3604 | i::Deoptimizer::DeoptimizeGlobalObject(*obj); |
| 3605 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3606 | i::Handle<i::Map> new_map = |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 3607 | isolate->factory()->CopyMap(i::Handle<i::Map>(obj->map())); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3608 | new_map->set_is_access_check_needed(true); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3609 | obj->set_map(*new_map); |
| 3610 | } |
| 3611 | |
| 3612 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 3613 | bool v8::Object::IsDirty() { |
| 3614 | return Utils::OpenHandle(this)->IsDirty(); |
| 3615 | } |
| 3616 | |
| 3617 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3618 | Local<v8::Object> v8::Object::Clone() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3619 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3620 | ON_BAILOUT(isolate, "v8::Object::Clone()", return Local<Object>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3621 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3622 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3623 | EXCEPTION_PREAMBLE(isolate); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3624 | i::Handle<i::JSObject> result = i::JSObject::Copy(self); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3625 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3626 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3627 | return Utils::ToLocal(result); |
| 3628 | } |
| 3629 | |
| 3630 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3631 | static i::Context* GetCreationContext(i::JSObject* object) { |
| 3632 | i::Object* constructor = object->map()->constructor(); |
| 3633 | i::JSFunction* function; |
| 3634 | if (!constructor->IsJSFunction()) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3635 | // Functions have null as a constructor, |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3636 | // but any JSFunction knows its context immediately. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3637 | ASSERT(object->IsJSFunction()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3638 | function = i::JSFunction::cast(object); |
| 3639 | } else { |
| 3640 | function = i::JSFunction::cast(constructor); |
| 3641 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3642 | return function->context()->native_context(); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | |
| 3646 | Local<v8::Context> v8::Object::CreationContext() { |
| 3647 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3648 | ON_BAILOUT(isolate, |
| 3649 | "v8::Object::CreationContext()", return Local<v8::Context>()); |
| 3650 | ENTER_V8(isolate); |
| 3651 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3652 | i::Context* context = GetCreationContext(*self); |
| 3653 | return Utils::ToLocal(i::Handle<i::Context>(context)); |
| 3654 | } |
| 3655 | |
| 3656 | |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3657 | int v8::Object::GetIdentityHash() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3658 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3659 | ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3660 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3661 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3662 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 3663 | return i::Handle<i::Smi>::cast( |
| 3664 | i::JSReceiver::GetOrCreateIdentityHash(self))->value(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | |
| 3668 | bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, |
| 3669 | v8::Handle<v8::Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3670 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3671 | ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 3672 | if (value.IsEmpty()) return DeleteHiddenValue(key); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3673 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3674 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3675 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3676 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3677 | i::Handle<i::String> key_string = |
| 3678 | isolate->factory()->InternalizeString(key_obj); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3679 | i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3680 | i::Handle<i::Object> result = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3681 | i::JSObject::SetHiddenProperty(self, key_string, value_obj); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3682 | return *result == *self; |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3683 | } |
| 3684 | |
| 3685 | |
| 3686 | 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] | 3687 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3688 | ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()", |
| 3689 | return Local<v8::Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3690 | ENTER_V8(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3691 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3692 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3693 | i::Handle<i::String> key_string = |
| 3694 | isolate->factory()->InternalizeString(key_obj); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3695 | i::Handle<i::Object> result(self->GetHiddenProperty(*key_string), isolate); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3696 | if (result->IsTheHole()) return v8::Local<v8::Value>(); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3697 | return Utils::ToLocal(result); |
| 3698 | } |
| 3699 | |
| 3700 | |
| 3701 | bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3702 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3703 | ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3704 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3705 | i::HandleScope scope(isolate); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3706 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3707 | i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3708 | i::Handle<i::String> key_string = |
| 3709 | isolate->factory()->InternalizeString(key_obj); |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 3710 | i::JSObject::DeleteHiddenProperty(self, key_string); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3711 | return true; |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 3712 | } |
| 3713 | |
| 3714 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3715 | namespace { |
| 3716 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3717 | static i::ElementsKind GetElementsKindFromExternalArrayType( |
| 3718 | ExternalArrayType array_type) { |
| 3719 | switch (array_type) { |
| 3720 | case kExternalByteArray: |
| 3721 | return i::EXTERNAL_BYTE_ELEMENTS; |
| 3722 | break; |
| 3723 | case kExternalUnsignedByteArray: |
| 3724 | return i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS; |
| 3725 | break; |
| 3726 | case kExternalShortArray: |
| 3727 | return i::EXTERNAL_SHORT_ELEMENTS; |
| 3728 | break; |
| 3729 | case kExternalUnsignedShortArray: |
| 3730 | return i::EXTERNAL_UNSIGNED_SHORT_ELEMENTS; |
| 3731 | break; |
| 3732 | case kExternalIntArray: |
| 3733 | return i::EXTERNAL_INT_ELEMENTS; |
| 3734 | break; |
| 3735 | case kExternalUnsignedIntArray: |
| 3736 | return i::EXTERNAL_UNSIGNED_INT_ELEMENTS; |
| 3737 | break; |
| 3738 | case kExternalFloatArray: |
| 3739 | return i::EXTERNAL_FLOAT_ELEMENTS; |
| 3740 | break; |
| 3741 | case kExternalDoubleArray: |
| 3742 | return i::EXTERNAL_DOUBLE_ELEMENTS; |
| 3743 | break; |
| 3744 | case kExternalPixelArray: |
| 3745 | return i::EXTERNAL_PIXEL_ELEMENTS; |
| 3746 | break; |
| 3747 | } |
| 3748 | UNREACHABLE(); |
| 3749 | return i::DICTIONARY_ELEMENTS; |
| 3750 | } |
| 3751 | |
| 3752 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3753 | void PrepareExternalArrayElements(i::Handle<i::JSObject> object, |
| 3754 | void* data, |
| 3755 | ExternalArrayType array_type, |
| 3756 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3757 | i::Isolate* isolate = object->GetIsolate(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3758 | i::Handle<i::ExternalArray> array = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3759 | isolate->factory()->NewExternalArray(length, array_type, data); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3760 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3761 | i::Handle<i::Map> external_array_map = |
| 3762 | isolate->factory()->GetElementsTransitionMap( |
| 3763 | object, |
| 3764 | GetElementsKindFromExternalArrayType(array_type)); |
| 3765 | |
| 3766 | object->set_map(*external_array_map); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3767 | object->set_elements(*array); |
| 3768 | } |
| 3769 | |
| 3770 | } // namespace |
| 3771 | |
| 3772 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3773 | void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3774 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3775 | ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3776 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3777 | i::HandleScope scope(isolate); |
danno@chromium.org | 412fa51 | 2012-09-14 13:28:26 +0000 | [diff] [blame] | 3778 | if (!ApiCheck(length >= 0 && length <= i::ExternalPixelArray::kMaxLength, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3779 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3780 | "length exceeds max acceptable value")) { |
| 3781 | return; |
| 3782 | } |
| 3783 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3784 | if (!ApiCheck(!self->IsJSArray(), |
| 3785 | "v8::Object::SetIndexedPropertiesToPixelData()", |
| 3786 | "JSArray is not supported")) { |
| 3787 | return; |
| 3788 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3789 | PrepareExternalArrayElements(self, data, kExternalPixelArray, length); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3793 | bool v8::Object::HasIndexedPropertiesInPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3794 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3795 | ON_BAILOUT(self->GetIsolate(), "v8::HasIndexedPropertiesInPixelData()", |
| 3796 | return false); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3797 | return self->HasExternalPixelElements(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | |
| 3801 | uint8_t* v8::Object::GetIndexedPropertiesPixelData() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3802 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3803 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelData()", |
| 3804 | return NULL); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3805 | if (self->HasExternalPixelElements()) { |
| 3806 | return i::ExternalPixelArray::cast(self->elements())-> |
| 3807 | external_pixel_pointer(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3808 | } else { |
| 3809 | return NULL; |
| 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | |
| 3814 | int v8::Object::GetIndexedPropertiesPixelDataLength() { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3815 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3816 | ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelDataLength()", |
| 3817 | return -1); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3818 | if (self->HasExternalPixelElements()) { |
| 3819 | return i::ExternalPixelArray::cast(self->elements())->length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3820 | } else { |
| 3821 | return -1; |
| 3822 | } |
| 3823 | } |
| 3824 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3825 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3826 | void v8::Object::SetIndexedPropertiesToExternalArrayData( |
| 3827 | void* data, |
| 3828 | ExternalArrayType array_type, |
| 3829 | int length) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3830 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3831 | ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3832 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3833 | i::HandleScope scope(isolate); |
danno@chromium.org | 412fa51 | 2012-09-14 13:28:26 +0000 | [diff] [blame] | 3834 | if (!ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength, |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3835 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3836 | "length exceeds max acceptable value")) { |
| 3837 | return; |
| 3838 | } |
| 3839 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3840 | if (!ApiCheck(!self->IsJSArray(), |
| 3841 | "v8::Object::SetIndexedPropertiesToExternalArrayData()", |
| 3842 | "JSArray is not supported")) { |
| 3843 | return; |
| 3844 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3845 | PrepareExternalArrayElements(self, data, array_type, length); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3849 | bool v8::Object::HasIndexedPropertiesInExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3850 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3851 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3852 | "v8::HasIndexedPropertiesInExternalArrayData()", |
| 3853 | return false); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3854 | return self->HasExternalArrayElements(); |
| 3855 | } |
| 3856 | |
| 3857 | |
| 3858 | void* v8::Object::GetIndexedPropertiesExternalArrayData() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3859 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3860 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3861 | "v8::GetIndexedPropertiesExternalArrayData()", |
| 3862 | return NULL); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3863 | if (self->HasExternalArrayElements()) { |
| 3864 | return i::ExternalArray::cast(self->elements())->external_pointer(); |
| 3865 | } else { |
| 3866 | return NULL; |
| 3867 | } |
| 3868 | } |
| 3869 | |
| 3870 | |
| 3871 | ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3872 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3873 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3874 | "v8::GetIndexedPropertiesExternalArrayDataType()", |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3875 | return static_cast<ExternalArrayType>(-1)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3876 | switch (self->elements()->map()->instance_type()) { |
| 3877 | case i::EXTERNAL_BYTE_ARRAY_TYPE: |
| 3878 | return kExternalByteArray; |
| 3879 | case i::EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 3880 | return kExternalUnsignedByteArray; |
| 3881 | case i::EXTERNAL_SHORT_ARRAY_TYPE: |
| 3882 | return kExternalShortArray; |
| 3883 | case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 3884 | return kExternalUnsignedShortArray; |
| 3885 | case i::EXTERNAL_INT_ARRAY_TYPE: |
| 3886 | return kExternalIntArray; |
| 3887 | case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 3888 | return kExternalUnsignedIntArray; |
| 3889 | case i::EXTERNAL_FLOAT_ARRAY_TYPE: |
| 3890 | return kExternalFloatArray; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3891 | case i::EXTERNAL_DOUBLE_ARRAY_TYPE: |
| 3892 | return kExternalDoubleArray; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3893 | case i::EXTERNAL_PIXEL_ARRAY_TYPE: |
| 3894 | return kExternalPixelArray; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3895 | default: |
| 3896 | return static_cast<ExternalArrayType>(-1); |
| 3897 | } |
| 3898 | } |
| 3899 | |
| 3900 | |
| 3901 | int v8::Object::GetIndexedPropertiesExternalArrayDataLength() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3902 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3903 | ON_BAILOUT(self->GetIsolate(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3904 | "v8::GetIndexedPropertiesExternalArrayDataLength()", |
| 3905 | return 0); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3906 | if (self->HasExternalArrayElements()) { |
| 3907 | return i::ExternalArray::cast(self->elements())->length(); |
| 3908 | } else { |
| 3909 | return -1; |
| 3910 | } |
| 3911 | } |
| 3912 | |
| 3913 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3914 | bool v8::Object::IsCallable() { |
| 3915 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3916 | ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false); |
| 3917 | ENTER_V8(isolate); |
| 3918 | i::HandleScope scope(isolate); |
| 3919 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
machenbach@chromium.org | 9f18d91 | 2013-11-28 13:42:41 +0000 | [diff] [blame] | 3920 | return obj->IsCallable(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3924 | Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Value> recv, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3925 | int argc, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3926 | v8::Handle<v8::Value> argv[]) { |
| 3927 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3928 | ON_BAILOUT(isolate, "v8::Object::CallAsFunction()", |
| 3929 | return Local<v8::Value>()); |
| 3930 | LOG_API(isolate, "Object::CallAsFunction"); |
| 3931 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3932 | i::Logger::TimerEventScope timer_scope( |
| 3933 | isolate, i::Logger::TimerEventScope::v8_execute); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3934 | i::HandleScope scope(isolate); |
| 3935 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3936 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 3937 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3938 | 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] | 3939 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>(); |
| 3940 | if (obj->IsJSFunction()) { |
| 3941 | fun = i::Handle<i::JSFunction>::cast(obj); |
| 3942 | } else { |
| 3943 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3944 | i::Handle<i::Object> delegate = i::Execution::TryGetFunctionDelegate( |
| 3945 | isolate, obj, &has_pending_exception); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3946 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3947 | fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3948 | recv_obj = obj; |
| 3949 | } |
| 3950 | EXCEPTION_PREAMBLE(isolate); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 3951 | i::Handle<i::Object> returned = i::Execution::Call( |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 3952 | isolate, fun, recv_obj, argc, args, &has_pending_exception, true); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3953 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3954 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3955 | } |
| 3956 | |
| 3957 | |
| 3958 | Local<v8::Value> Object::CallAsConstructor(int argc, |
| 3959 | v8::Handle<v8::Value> argv[]) { |
| 3960 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3961 | ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()", |
| 3962 | return Local<v8::Object>()); |
| 3963 | LOG_API(isolate, "Object::CallAsConstructor"); |
| 3964 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3965 | i::Logger::TimerEventScope timer_scope( |
| 3966 | isolate, i::Logger::TimerEventScope::v8_execute); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3967 | i::HandleScope scope(isolate); |
| 3968 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3969 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 3970 | 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] | 3971 | if (obj->IsJSFunction()) { |
| 3972 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj); |
| 3973 | EXCEPTION_PREAMBLE(isolate); |
| 3974 | i::Handle<i::Object> returned = |
| 3975 | i::Execution::New(fun, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3976 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3977 | return Utils::ToLocal(scope.CloseAndEscape( |
| 3978 | i::Handle<i::JSObject>::cast(returned))); |
| 3979 | } |
| 3980 | EXCEPTION_PREAMBLE(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3981 | i::Handle<i::Object> delegate = i::Execution::TryGetConstructorDelegate( |
| 3982 | isolate, obj, &has_pending_exception); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3983 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3984 | if (!delegate->IsUndefined()) { |
| 3985 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3986 | EXCEPTION_PREAMBLE(isolate); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 3987 | i::Handle<i::Object> returned = i::Execution::Call( |
| 3988 | isolate, fun, obj, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3989 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3990 | ASSERT(!delegate->IsUndefined()); |
| 3991 | return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3992 | } |
| 3993 | return Local<v8::Object>(); |
| 3994 | } |
| 3995 | |
| 3996 | |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 3997 | Local<Function> Function::New(Isolate* v8_isolate, |
| 3998 | FunctionCallback callback, |
| 3999 | Local<Value> data, |
| 4000 | int length) { |
| 4001 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 4002 | LOG_API(isolate, "Function::New"); |
| 4003 | ENTER_V8(isolate); |
| 4004 | return FunctionTemplateNew( |
| 4005 | isolate, callback, data, Local<Signature>(), length, true)-> |
| 4006 | GetFunction(); |
| 4007 | } |
| 4008 | |
| 4009 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4010 | Local<v8::Object> Function::NewInstance() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4011 | return NewInstance(0, NULL); |
| 4012 | } |
| 4013 | |
| 4014 | |
| 4015 | Local<v8::Object> Function::NewInstance(int argc, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4016 | v8::Handle<v8::Value> argv[]) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4017 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4018 | ON_BAILOUT(isolate, "v8::Function::NewInstance()", |
| 4019 | return Local<v8::Object>()); |
| 4020 | LOG_API(isolate, "Function::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4021 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4022 | i::Logger::TimerEventScope timer_scope( |
| 4023 | isolate, i::Logger::TimerEventScope::v8_execute); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 4024 | EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4025 | i::Handle<i::JSFunction> function = Utils::OpenHandle(this); |
| 4026 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 4027 | 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] | 4028 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4029 | i::Handle<i::Object> returned = |
| 4030 | i::Execution::New(function, argc, args, &has_pending_exception); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4031 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 4032 | return scope.Escape(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4036 | 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] | 4037 | v8::Handle<v8::Value> argv[]) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4038 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4039 | ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>()); |
| 4040 | LOG_API(isolate, "Function::Call"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4041 | ENTER_V8(isolate); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 4042 | i::Logger::TimerEventScope timer_scope( |
| 4043 | isolate, i::Logger::TimerEventScope::v8_execute); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4044 | i::Object* raw_result = NULL; |
| 4045 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4046 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4047 | i::Handle<i::JSFunction> fun = Utils::OpenHandle(this); |
| 4048 | i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 4049 | STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 4050 | 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] | 4051 | EXCEPTION_PREAMBLE(isolate); |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 4052 | i::Handle<i::Object> returned = i::Execution::Call( |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 4053 | isolate, fun, recv_obj, argc, args, &has_pending_exception, true); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4054 | EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4055 | raw_result = *returned; |
| 4056 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 4057 | i::Handle<i::Object> result(raw_result, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4058 | return Utils::ToLocal(result); |
| 4059 | } |
| 4060 | |
| 4061 | |
| 4062 | void Function::SetName(v8::Handle<v8::String> name) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4063 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 4064 | ENTER_V8(isolate); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4065 | USE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4066 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4067 | func->shared()->set_name(*Utils::OpenHandle(*name)); |
| 4068 | } |
| 4069 | |
| 4070 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4071 | Handle<Value> Function::GetName() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4072 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 4073 | return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name(), |
| 4074 | func->GetIsolate())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 4078 | Handle<Value> Function::GetInferredName() const { |
| 4079 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 4080 | return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(), |
| 4081 | func->GetIsolate())); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 4085 | Handle<Value> Function::GetDisplayName() const { |
| 4086 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 4087 | ON_BAILOUT(isolate, "v8::Function::GetDisplayName()", |
| 4088 | return ToApiHandle<Primitive>( |
| 4089 | isolate->factory()->undefined_value())); |
| 4090 | ENTER_V8(isolate); |
| 4091 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4092 | i::Handle<i::String> property_name = |
| 4093 | isolate->factory()->InternalizeOneByteString( |
| 4094 | STATIC_ASCII_VECTOR("displayName")); |
| 4095 | i::LookupResult lookup(isolate); |
| 4096 | func->LookupRealNamedProperty(*property_name, &lookup); |
| 4097 | if (lookup.IsFound()) { |
| 4098 | i::Object* value = lookup.GetLazyValue(); |
| 4099 | if (value && value->IsString()) { |
| 4100 | i::String* name = i::String::cast(value); |
| 4101 | if (name->length() > 0) return Utils::ToLocal(i::Handle<i::String>(name)); |
| 4102 | } |
| 4103 | } |
| 4104 | return ToApiHandle<Primitive>(isolate->factory()->undefined_value()); |
| 4105 | } |
| 4106 | |
| 4107 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4108 | ScriptOrigin Function::GetScriptOrigin() const { |
| 4109 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4110 | if (func->shared()->script()->IsScript()) { |
| 4111 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4112 | i::Handle<i::Object> scriptName = GetScriptNameOrSourceURL(script); |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 4113 | v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(func->GetIsolate()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4114 | v8::ScriptOrigin origin( |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4115 | Utils::ToLocal(scriptName), |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 4116 | v8::Integer::New(isolate, script->line_offset()->value()), |
| 4117 | v8::Integer::New(isolate, script->column_offset()->value())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4118 | return origin; |
| 4119 | } |
| 4120 | return v8::ScriptOrigin(Handle<Value>()); |
| 4121 | } |
| 4122 | |
| 4123 | |
| 4124 | const int Function::kLineOffsetNotFound = -1; |
| 4125 | |
| 4126 | |
| 4127 | int Function::GetScriptLineNumber() const { |
| 4128 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4129 | if (func->shared()->script()->IsScript()) { |
| 4130 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 4131 | return i::GetScriptLineNumber(script, func->shared()->start_position()); |
| 4132 | } |
| 4133 | return kLineOffsetNotFound; |
| 4134 | } |
| 4135 | |
| 4136 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4137 | int Function::GetScriptColumnNumber() const { |
| 4138 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4139 | if (func->shared()->script()->IsScript()) { |
| 4140 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 4141 | return i::GetScriptColumnNumber(script, func->shared()->start_position()); |
| 4142 | } |
| 4143 | return kLineOffsetNotFound; |
| 4144 | } |
| 4145 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4146 | |
bmeurer@chromium.org | db78329 | 2013-10-23 06:51:00 +0000 | [diff] [blame] | 4147 | bool Function::IsBuiltin() const { |
| 4148 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4149 | return func->IsBuiltin(); |
| 4150 | } |
| 4151 | |
| 4152 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4153 | int Function::ScriptId() const { |
| 4154 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4155 | if (!func->shared()->script()->IsScript()) return v8::Script::kNoScriptId; |
| 4156 | i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
| 4157 | return script->id()->value(); |
| 4158 | } |
| 4159 | |
| 4160 | |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 4161 | Local<v8::Value> Function::GetBoundFunction() const { |
| 4162 | i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
| 4163 | if (!func->shared()->bound()) { |
| 4164 | return v8::Undefined(reinterpret_cast<v8::Isolate*>(func->GetIsolate())); |
| 4165 | } |
| 4166 | i::Handle<i::FixedArray> bound_args = i::Handle<i::FixedArray>( |
| 4167 | i::FixedArray::cast(func->function_bindings())); |
| 4168 | i::Handle<i::Object> original( |
| 4169 | bound_args->get(i::JSFunction::kBoundFunctionIndex), |
| 4170 | func->GetIsolate()); |
| 4171 | return Utils::ToLocal(i::Handle<i::JSFunction>::cast(original)); |
| 4172 | } |
| 4173 | |
| 4174 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4175 | int String::Length() const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4176 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4177 | return str->length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4178 | } |
| 4179 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 4180 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4181 | bool String::IsOneByte() const { |
| 4182 | i::Handle<i::String> str = Utils::OpenHandle(this); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 4183 | return str->HasOnlyOneByteChars(); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4184 | } |
| 4185 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 4186 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 4187 | // Helpers for ContainsOnlyOneByteHelper |
| 4188 | template<size_t size> struct OneByteMask; |
| 4189 | template<> struct OneByteMask<4> { |
| 4190 | static const uint32_t value = 0xFF00FF00; |
| 4191 | }; |
| 4192 | template<> struct OneByteMask<8> { |
| 4193 | static const uint64_t value = V8_2PART_UINT64_C(0xFF00FF00, FF00FF00); |
| 4194 | }; |
| 4195 | static const uintptr_t kOneByteMask = OneByteMask<sizeof(uintptr_t)>::value; |
| 4196 | static const uintptr_t kAlignmentMask = sizeof(uintptr_t) - 1; |
| 4197 | static inline bool Unaligned(const uint16_t* chars) { |
| 4198 | return reinterpret_cast<const uintptr_t>(chars) & kAlignmentMask; |
| 4199 | } |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 4200 | |
| 4201 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 4202 | static inline const uint16_t* Align(const uint16_t* chars) { |
| 4203 | return reinterpret_cast<uint16_t*>( |
| 4204 | reinterpret_cast<uintptr_t>(chars) & ~kAlignmentMask); |
| 4205 | } |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4206 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4207 | class ContainsOnlyOneByteHelper { |
| 4208 | public: |
| 4209 | ContainsOnlyOneByteHelper() : is_one_byte_(true) {} |
| 4210 | bool Check(i::String* string) { |
| 4211 | i::ConsString* cons_string = i::String::VisitFlat(this, string, 0); |
| 4212 | if (cons_string == NULL) return is_one_byte_; |
| 4213 | return CheckCons(cons_string); |
| 4214 | } |
| 4215 | void VisitOneByteString(const uint8_t* chars, int length) { |
| 4216 | // Nothing to do. |
| 4217 | } |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4218 | void VisitTwoByteString(const uint16_t* chars, int length) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 4219 | // Accumulated bits. |
| 4220 | uintptr_t acc = 0; |
| 4221 | // Align to uintptr_t. |
| 4222 | const uint16_t* end = chars + length; |
| 4223 | while (Unaligned(chars) && chars != end) { |
| 4224 | acc |= *chars++; |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4225 | } |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 4226 | // Read word aligned in blocks, |
| 4227 | // checking the return value at the end of each block. |
| 4228 | const uint16_t* aligned_end = Align(end); |
| 4229 | const int increment = sizeof(uintptr_t)/sizeof(uint16_t); |
| 4230 | const int inner_loops = 16; |
| 4231 | while (chars + inner_loops*increment < aligned_end) { |
| 4232 | for (int i = 0; i < inner_loops; i++) { |
| 4233 | acc |= *reinterpret_cast<const uintptr_t*>(chars); |
| 4234 | chars += increment; |
| 4235 | } |
| 4236 | // Check for early return. |
| 4237 | if ((acc & kOneByteMask) != 0) { |
| 4238 | is_one_byte_ = false; |
| 4239 | return; |
| 4240 | } |
| 4241 | } |
| 4242 | // Read the rest. |
| 4243 | while (chars != end) { |
| 4244 | acc |= *chars++; |
| 4245 | } |
| 4246 | // Check result. |
| 4247 | if ((acc & kOneByteMask) != 0) is_one_byte_ = false; |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | private: |
| 4251 | bool CheckCons(i::ConsString* cons_string) { |
| 4252 | while (true) { |
| 4253 | // Check left side if flat. |
| 4254 | i::String* left = cons_string->first(); |
| 4255 | i::ConsString* left_as_cons = |
| 4256 | i::String::VisitFlat(this, left, 0); |
| 4257 | if (!is_one_byte_) return false; |
| 4258 | // Check right side if flat. |
| 4259 | i::String* right = cons_string->second(); |
| 4260 | i::ConsString* right_as_cons = |
| 4261 | i::String::VisitFlat(this, right, 0); |
| 4262 | if (!is_one_byte_) return false; |
| 4263 | // Standard recurse/iterate trick. |
| 4264 | if (left_as_cons != NULL && right_as_cons != NULL) { |
| 4265 | if (left->length() < right->length()) { |
| 4266 | CheckCons(left_as_cons); |
| 4267 | cons_string = right_as_cons; |
| 4268 | } else { |
| 4269 | CheckCons(right_as_cons); |
| 4270 | cons_string = left_as_cons; |
| 4271 | } |
| 4272 | // Check fast return. |
| 4273 | if (!is_one_byte_) return false; |
| 4274 | continue; |
| 4275 | } |
| 4276 | // Descend left in place. |
| 4277 | if (left_as_cons != NULL) { |
| 4278 | cons_string = left_as_cons; |
| 4279 | continue; |
| 4280 | } |
| 4281 | // Descend right in place. |
| 4282 | if (right_as_cons != NULL) { |
| 4283 | cons_string = right_as_cons; |
| 4284 | continue; |
| 4285 | } |
| 4286 | // Terminate. |
| 4287 | break; |
| 4288 | } |
| 4289 | return is_one_byte_; |
| 4290 | } |
| 4291 | bool is_one_byte_; |
| 4292 | DISALLOW_COPY_AND_ASSIGN(ContainsOnlyOneByteHelper); |
| 4293 | }; |
| 4294 | |
| 4295 | |
| 4296 | bool String::ContainsOnlyOneByte() const { |
| 4297 | i::Handle<i::String> str = Utils::OpenHandle(this); |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4298 | if (str->HasOnlyOneByteChars()) return true; |
| 4299 | ContainsOnlyOneByteHelper helper; |
| 4300 | return helper.Check(*str); |
| 4301 | } |
| 4302 | |
| 4303 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4304 | class Utf8LengthHelper : public i::AllStatic { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4305 | public: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4306 | enum State { |
| 4307 | kEndsWithLeadingSurrogate = 1 << 0, |
| 4308 | kStartsWithTrailingSurrogate = 1 << 1, |
| 4309 | kLeftmostEdgeIsCalculated = 1 << 2, |
| 4310 | kRightmostEdgeIsCalculated = 1 << 3, |
| 4311 | kLeftmostEdgeIsSurrogate = 1 << 4, |
| 4312 | kRightmostEdgeIsSurrogate = 1 << 5 |
| 4313 | }; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4314 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4315 | static const uint8_t kInitialState = 0; |
| 4316 | |
| 4317 | static inline bool EndsWithSurrogate(uint8_t state) { |
| 4318 | return state & kEndsWithLeadingSurrogate; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4319 | } |
| 4320 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4321 | static inline bool StartsWithSurrogate(uint8_t state) { |
| 4322 | return state & kStartsWithTrailingSurrogate; |
| 4323 | } |
| 4324 | |
| 4325 | class Visitor { |
| 4326 | public: |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4327 | inline explicit Visitor() |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4328 | : utf8_length_(0), |
| 4329 | state_(kInitialState) {} |
| 4330 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4331 | void VisitOneByteString(const uint8_t* chars, int length) { |
| 4332 | int utf8_length = 0; |
| 4333 | // Add in length 1 for each non-ASCII character. |
| 4334 | for (int i = 0; i < length; i++) { |
| 4335 | utf8_length += *chars++ >> 7; |
| 4336 | } |
| 4337 | // Add in length 1 for each character. |
| 4338 | utf8_length_ = utf8_length + length; |
| 4339 | state_ = kInitialState; |
| 4340 | } |
| 4341 | |
| 4342 | void VisitTwoByteString(const uint16_t* chars, int length) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4343 | int utf8_length = 0; |
| 4344 | int last_character = unibrow::Utf16::kNoPreviousCharacter; |
| 4345 | for (int i = 0; i < length; i++) { |
| 4346 | uint16_t c = chars[i]; |
| 4347 | utf8_length += unibrow::Utf8::Length(c, last_character); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4348 | last_character = c; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4349 | } |
| 4350 | utf8_length_ = utf8_length; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4351 | uint8_t state = 0; |
| 4352 | if (unibrow::Utf16::IsTrailSurrogate(chars[0])) { |
| 4353 | state |= kStartsWithTrailingSurrogate; |
| 4354 | } |
| 4355 | if (unibrow::Utf16::IsLeadSurrogate(chars[length-1])) { |
| 4356 | state |= kEndsWithLeadingSurrogate; |
| 4357 | } |
| 4358 | state_ = state; |
| 4359 | } |
| 4360 | |
| 4361 | static i::ConsString* VisitFlat(i::String* string, |
| 4362 | int* length, |
| 4363 | uint8_t* state) { |
| 4364 | Visitor visitor; |
| 4365 | i::ConsString* cons_string = i::String::VisitFlat(&visitor, string); |
| 4366 | *length = visitor.utf8_length_; |
| 4367 | *state = visitor.state_; |
| 4368 | return cons_string; |
| 4369 | } |
| 4370 | |
| 4371 | private: |
| 4372 | int utf8_length_; |
| 4373 | uint8_t state_; |
| 4374 | DISALLOW_COPY_AND_ASSIGN(Visitor); |
| 4375 | }; |
| 4376 | |
| 4377 | static inline void MergeLeafLeft(int* length, |
| 4378 | uint8_t* state, |
| 4379 | uint8_t leaf_state) { |
| 4380 | bool edge_surrogate = StartsWithSurrogate(leaf_state); |
| 4381 | if (!(*state & kLeftmostEdgeIsCalculated)) { |
| 4382 | ASSERT(!(*state & kLeftmostEdgeIsSurrogate)); |
| 4383 | *state |= kLeftmostEdgeIsCalculated |
| 4384 | | (edge_surrogate ? kLeftmostEdgeIsSurrogate : 0); |
| 4385 | } else if (EndsWithSurrogate(*state) && edge_surrogate) { |
| 4386 | *length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates; |
| 4387 | } |
| 4388 | if (EndsWithSurrogate(leaf_state)) { |
| 4389 | *state |= kEndsWithLeadingSurrogate; |
| 4390 | } else { |
| 4391 | *state &= ~kEndsWithLeadingSurrogate; |
| 4392 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4393 | } |
| 4394 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4395 | static inline void MergeLeafRight(int* length, |
| 4396 | uint8_t* state, |
| 4397 | uint8_t leaf_state) { |
| 4398 | bool edge_surrogate = EndsWithSurrogate(leaf_state); |
| 4399 | if (!(*state & kRightmostEdgeIsCalculated)) { |
| 4400 | ASSERT(!(*state & kRightmostEdgeIsSurrogate)); |
| 4401 | *state |= (kRightmostEdgeIsCalculated |
| 4402 | | (edge_surrogate ? kRightmostEdgeIsSurrogate : 0)); |
| 4403 | } else if (edge_surrogate && StartsWithSurrogate(*state)) { |
| 4404 | *length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates; |
| 4405 | } |
| 4406 | if (StartsWithSurrogate(leaf_state)) { |
| 4407 | *state |= kStartsWithTrailingSurrogate; |
| 4408 | } else { |
| 4409 | *state &= ~kStartsWithTrailingSurrogate; |
| 4410 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4411 | } |
| 4412 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4413 | static inline void MergeTerminal(int* length, |
| 4414 | uint8_t state, |
| 4415 | uint8_t* state_out) { |
| 4416 | ASSERT((state & kLeftmostEdgeIsCalculated) && |
| 4417 | (state & kRightmostEdgeIsCalculated)); |
| 4418 | if (EndsWithSurrogate(state) && StartsWithSurrogate(state)) { |
| 4419 | *length -= unibrow::Utf8::kBytesSavedByCombiningSurrogates; |
| 4420 | } |
| 4421 | *state_out = kInitialState | |
| 4422 | (state & kLeftmostEdgeIsSurrogate ? kStartsWithTrailingSurrogate : 0) | |
| 4423 | (state & kRightmostEdgeIsSurrogate ? kEndsWithLeadingSurrogate : 0); |
| 4424 | } |
| 4425 | |
| 4426 | static int Calculate(i::ConsString* current, uint8_t* state_out) { |
| 4427 | using namespace internal; |
| 4428 | int total_length = 0; |
| 4429 | uint8_t state = kInitialState; |
| 4430 | while (true) { |
| 4431 | i::String* left = current->first(); |
| 4432 | i::String* right = current->second(); |
| 4433 | uint8_t right_leaf_state; |
| 4434 | uint8_t left_leaf_state; |
| 4435 | int leaf_length; |
| 4436 | ConsString* left_as_cons = |
| 4437 | Visitor::VisitFlat(left, &leaf_length, &left_leaf_state); |
| 4438 | if (left_as_cons == NULL) { |
| 4439 | total_length += leaf_length; |
| 4440 | MergeLeafLeft(&total_length, &state, left_leaf_state); |
| 4441 | } |
| 4442 | ConsString* right_as_cons = |
| 4443 | Visitor::VisitFlat(right, &leaf_length, &right_leaf_state); |
| 4444 | if (right_as_cons == NULL) { |
| 4445 | total_length += leaf_length; |
| 4446 | MergeLeafRight(&total_length, &state, right_leaf_state); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4447 | if (left_as_cons != NULL) { |
| 4448 | // 1 Leaf node. Descend in place. |
| 4449 | current = left_as_cons; |
| 4450 | continue; |
| 4451 | } else { |
| 4452 | // Terminal node. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4453 | MergeTerminal(&total_length, state, state_out); |
| 4454 | return total_length; |
| 4455 | } |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4456 | } else if (left_as_cons == NULL) { |
| 4457 | // 1 Leaf node. Descend in place. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4458 | current = right_as_cons; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4459 | continue; |
| 4460 | } |
| 4461 | // Both strings are ConsStrings. |
| 4462 | // Recurse on smallest. |
| 4463 | if (left->length() < right->length()) { |
| 4464 | total_length += Calculate(left_as_cons, &left_leaf_state); |
| 4465 | MergeLeafLeft(&total_length, &state, left_leaf_state); |
| 4466 | current = right_as_cons; |
| 4467 | } else { |
| 4468 | total_length += Calculate(right_as_cons, &right_leaf_state); |
| 4469 | MergeLeafRight(&total_length, &state, right_leaf_state); |
| 4470 | current = left_as_cons; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4471 | } |
| 4472 | } |
| 4473 | UNREACHABLE(); |
| 4474 | return 0; |
| 4475 | } |
| 4476 | |
| 4477 | static inline int Calculate(i::ConsString* current) { |
| 4478 | uint8_t state = kInitialState; |
| 4479 | return Calculate(current, &state); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | private: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4483 | DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8LengthHelper); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4484 | }; |
| 4485 | |
| 4486 | |
| 4487 | static int Utf8Length(i::String* str, i::Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4488 | int length = str->length(); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4489 | if (length == 0) return 0; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4490 | uint8_t state; |
| 4491 | i::ConsString* cons_string = |
| 4492 | Utf8LengthHelper::Visitor::VisitFlat(str, &length, &state); |
| 4493 | if (cons_string == NULL) return length; |
| 4494 | return Utf8LengthHelper::Calculate(cons_string); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | |
| 4498 | int String::Utf8Length() const { |
| 4499 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 4500 | i::Isolate* isolate = str->GetIsolate(); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4501 | return v8::Utf8Length(*str, isolate); |
| 4502 | } |
| 4503 | |
| 4504 | |
| 4505 | class Utf8WriterVisitor { |
| 4506 | public: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4507 | Utf8WriterVisitor( |
| 4508 | char* buffer, int capacity, bool skip_capacity_check) |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4509 | : early_termination_(false), |
| 4510 | last_character_(unibrow::Utf16::kNoPreviousCharacter), |
| 4511 | buffer_(buffer), |
| 4512 | start_(buffer), |
| 4513 | capacity_(capacity), |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4514 | skip_capacity_check_(capacity == -1 || skip_capacity_check), |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4515 | utf16_chars_read_(0) { |
| 4516 | } |
| 4517 | |
| 4518 | static int WriteEndCharacter(uint16_t character, |
| 4519 | int last_character, |
| 4520 | int remaining, |
| 4521 | char* const buffer) { |
| 4522 | using namespace unibrow; |
| 4523 | ASSERT(remaining > 0); |
| 4524 | // We can't use a local buffer here because Encode needs to modify |
| 4525 | // previous characters in the stream. We know, however, that |
| 4526 | // exactly one character will be advanced. |
| 4527 | if (Utf16::IsTrailSurrogate(character) && |
| 4528 | Utf16::IsLeadSurrogate(last_character)) { |
| 4529 | int written = Utf8::Encode(buffer, character, last_character); |
| 4530 | ASSERT(written == 1); |
| 4531 | return written; |
| 4532 | } |
| 4533 | // Use a scratch buffer to check the required characters. |
| 4534 | char temp_buffer[Utf8::kMaxEncodedSize]; |
| 4535 | // Can't encode using last_character as gcc has array bounds issues. |
| 4536 | int written = Utf8::Encode(temp_buffer, |
| 4537 | character, |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4538 | Utf16::kNoPreviousCharacter); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4539 | // Won't fit. |
| 4540 | if (written > remaining) return 0; |
| 4541 | // Copy over the character from temp_buffer. |
| 4542 | for (int j = 0; j < written; j++) { |
| 4543 | buffer[j] = temp_buffer[j]; |
| 4544 | } |
| 4545 | return written; |
| 4546 | } |
| 4547 | |
| 4548 | template<typename Char> |
| 4549 | void Visit(const Char* chars, const int length) { |
| 4550 | using namespace unibrow; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4551 | ASSERT(!early_termination_); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4552 | if (length == 0) return; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4553 | // Copy state to stack. |
| 4554 | char* buffer = buffer_; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4555 | int last_character = |
| 4556 | sizeof(Char) == 1 ? Utf16::kNoPreviousCharacter : last_character_; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4557 | int i = 0; |
| 4558 | // Do a fast loop where there is no exit capacity check. |
| 4559 | while (true) { |
| 4560 | int fast_length; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4561 | if (skip_capacity_check_) { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4562 | fast_length = length; |
| 4563 | } else { |
| 4564 | int remaining_capacity = capacity_ - static_cast<int>(buffer - start_); |
| 4565 | // Need enough space to write everything but one character. |
| 4566 | STATIC_ASSERT(Utf16::kMaxExtraUtf8BytesForOneUtf16CodeUnit == 3); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4567 | int max_size_per_char = sizeof(Char) == 1 ? 2 : 3; |
| 4568 | int writable_length = |
| 4569 | (remaining_capacity - max_size_per_char)/max_size_per_char; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4570 | // Need to drop into slow loop. |
| 4571 | if (writable_length <= 0) break; |
| 4572 | fast_length = i + writable_length; |
| 4573 | if (fast_length > length) fast_length = length; |
| 4574 | } |
| 4575 | // Write the characters to the stream. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4576 | if (sizeof(Char) == 1) { |
| 4577 | for (; i < fast_length; i++) { |
| 4578 | buffer += |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 4579 | Utf8::EncodeOneByte(buffer, static_cast<uint8_t>(*chars++)); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4580 | ASSERT(capacity_ == -1 || (buffer - start_) <= capacity_); |
| 4581 | } |
| 4582 | } else { |
| 4583 | for (; i < fast_length; i++) { |
| 4584 | uint16_t character = *chars++; |
| 4585 | buffer += Utf8::Encode(buffer, character, last_character); |
| 4586 | last_character = character; |
| 4587 | ASSERT(capacity_ == -1 || (buffer - start_) <= capacity_); |
| 4588 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4589 | } |
| 4590 | // Array is fully written. Exit. |
| 4591 | if (fast_length == length) { |
| 4592 | // Write state back out to object. |
| 4593 | last_character_ = last_character; |
| 4594 | buffer_ = buffer; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4595 | utf16_chars_read_ += length; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4596 | return; |
| 4597 | } |
| 4598 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4599 | ASSERT(!skip_capacity_check_); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4600 | // Slow loop. Must check capacity on each iteration. |
| 4601 | int remaining_capacity = capacity_ - static_cast<int>(buffer - start_); |
| 4602 | ASSERT(remaining_capacity >= 0); |
| 4603 | for (; i < length && remaining_capacity > 0; i++) { |
| 4604 | uint16_t character = *chars++; |
| 4605 | int written = WriteEndCharacter(character, |
| 4606 | last_character, |
| 4607 | remaining_capacity, |
| 4608 | buffer); |
| 4609 | if (written == 0) { |
| 4610 | early_termination_ = true; |
| 4611 | break; |
| 4612 | } |
| 4613 | buffer += written; |
| 4614 | remaining_capacity -= written; |
| 4615 | last_character = character; |
| 4616 | } |
| 4617 | // Write state back out to object. |
| 4618 | last_character_ = last_character; |
| 4619 | buffer_ = buffer; |
| 4620 | utf16_chars_read_ += i; |
| 4621 | } |
| 4622 | |
| 4623 | inline bool IsDone() { |
| 4624 | return early_termination_; |
| 4625 | } |
| 4626 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4627 | inline void VisitOneByteString(const uint8_t* chars, int length) { |
| 4628 | Visit(chars, length); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4631 | inline void VisitTwoByteString(const uint16_t* chars, int length) { |
| 4632 | Visit(chars, length); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4633 | } |
| 4634 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4635 | int CompleteWrite(bool write_null, int* utf16_chars_read_out) { |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4636 | // Write out number of utf16 characters written to the stream. |
| 4637 | if (utf16_chars_read_out != NULL) { |
| 4638 | *utf16_chars_read_out = utf16_chars_read_; |
| 4639 | } |
| 4640 | // Only null terminate if all of the string was written and there's space. |
| 4641 | if (write_null && |
| 4642 | !early_termination_ && |
| 4643 | (capacity_ == -1 || (buffer_ - start_) < capacity_)) { |
| 4644 | *buffer_++ = '\0'; |
| 4645 | } |
| 4646 | return static_cast<int>(buffer_ - start_); |
| 4647 | } |
| 4648 | |
| 4649 | private: |
| 4650 | bool early_termination_; |
| 4651 | int last_character_; |
| 4652 | char* buffer_; |
| 4653 | char* const start_; |
| 4654 | int capacity_; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4655 | bool const skip_capacity_check_; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 4656 | int utf16_chars_read_; |
| 4657 | DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8WriterVisitor); |
| 4658 | }; |
| 4659 | |
| 4660 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4661 | static bool RecursivelySerializeToUtf8(i::String* current, |
| 4662 | Utf8WriterVisitor* writer, |
| 4663 | int recursion_budget) { |
| 4664 | while (!writer->IsDone()) { |
| 4665 | i::ConsString* cons_string = i::String::VisitFlat(writer, current); |
| 4666 | if (cons_string == NULL) return true; // Leaf node. |
| 4667 | if (recursion_budget <= 0) return false; |
| 4668 | // Must write the left branch first. |
| 4669 | i::String* first = cons_string->first(); |
| 4670 | bool success = RecursivelySerializeToUtf8(first, |
| 4671 | writer, |
| 4672 | recursion_budget - 1); |
| 4673 | if (!success) return false; |
| 4674 | // Inline tail recurse for right branch. |
| 4675 | current = cons_string->second(); |
| 4676 | } |
| 4677 | return true; |
| 4678 | } |
| 4679 | |
| 4680 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 4681 | int String::WriteUtf8(char* buffer, |
| 4682 | int capacity, |
| 4683 | int* nchars_ref, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 4684 | int options) const { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4685 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4686 | LOG_API(isolate, "String::WriteUtf8"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4687 | ENTER_V8(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4688 | i::Handle<i::String> str = Utils::OpenHandle(this); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 4689 | if (options & HINT_MANY_WRITES_EXPECTED) { |
| 4690 | FlattenString(str); // Flatten the string for efficiency. |
| 4691 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4692 | const int string_length = str->length(); |
| 4693 | bool write_null = !(options & NO_NULL_TERMINATION); |
| 4694 | // First check if we can just write the string without checking capacity. |
| 4695 | if (capacity == -1 || capacity / 3 >= string_length) { |
| 4696 | Utf8WriterVisitor writer(buffer, capacity, true); |
| 4697 | const int kMaxRecursion = 100; |
| 4698 | bool success = RecursivelySerializeToUtf8(*str, &writer, kMaxRecursion); |
| 4699 | if (success) return writer.CompleteWrite(write_null, nchars_ref); |
| 4700 | } else if (capacity >= string_length) { |
| 4701 | // First check that the buffer is large enough. |
| 4702 | int utf8_bytes = v8::Utf8Length(*str, str->GetIsolate()); |
| 4703 | if (utf8_bytes <= capacity) { |
| 4704 | // ASCII fast path. |
| 4705 | if (utf8_bytes == string_length) { |
| 4706 | WriteOneByte(reinterpret_cast<uint8_t*>(buffer), 0, capacity, options); |
| 4707 | if (nchars_ref != NULL) *nchars_ref = string_length; |
| 4708 | if (write_null && (utf8_bytes+1 <= capacity)) { |
| 4709 | return string_length + 1; |
| 4710 | } |
| 4711 | return string_length; |
| 4712 | } |
| 4713 | if (write_null && (utf8_bytes+1 > capacity)) { |
| 4714 | options |= NO_NULL_TERMINATION; |
| 4715 | } |
| 4716 | // Recurse once without a capacity limit. |
| 4717 | // This will get into the first branch above. |
| 4718 | // TODO(dcarney) Check max left rec. in Utf8Length and fall through. |
| 4719 | return WriteUtf8(buffer, -1, nchars_ref, options); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 4720 | } |
| 4721 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4722 | // Recursive slow path can potentially be unreasonable slow. Flatten. |
| 4723 | str = FlattenGetString(str); |
| 4724 | Utf8WriterVisitor writer(buffer, capacity, false); |
| 4725 | i::String::VisitFlat(&writer, *str); |
| 4726 | return writer.CompleteWrite(write_null, nchars_ref); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4727 | } |
| 4728 | |
| 4729 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4730 | template<typename CharType> |
| 4731 | static inline int WriteHelper(const String* string, |
| 4732 | CharType* buffer, |
| 4733 | int start, |
| 4734 | int length, |
| 4735 | int options) { |
| 4736 | i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate(); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4737 | LOG_API(isolate, "String::Write"); |
| 4738 | ENTER_V8(isolate); |
| 4739 | ASSERT(start >= 0 && length >= -1); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4740 | i::Handle<i::String> str = Utils::OpenHandle(string); |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4741 | isolate->string_tracker()->RecordWrite(str); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4742 | if (options & String::HINT_MANY_WRITES_EXPECTED) { |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4743 | // Flatten the string for efficiency. This applies whether we are |
| 4744 | // using StringCharacterStream or Get(i) to access the characters. |
| 4745 | FlattenString(str); |
| 4746 | } |
| 4747 | int end = start + length; |
| 4748 | if ((length == -1) || (length > str->length() - start) ) |
| 4749 | end = str->length(); |
| 4750 | if (end < 0) return 0; |
| 4751 | i::String::WriteToFlat(*str, buffer, start, end); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4752 | if (!(options & String::NO_NULL_TERMINATION) && |
yangguo@chromium.org | e19986e | 2013-01-16 09:48:20 +0000 | [diff] [blame] | 4753 | (length == -1 || end - start < length)) { |
| 4754 | buffer[end - start] = '\0'; |
| 4755 | } |
| 4756 | return end - start; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4757 | } |
| 4758 | |
| 4759 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 4760 | int String::WriteOneByte(uint8_t* buffer, |
| 4761 | int start, |
| 4762 | int length, |
| 4763 | int options) const { |
| 4764 | return WriteHelper(this, buffer, start, length, options); |
| 4765 | } |
| 4766 | |
| 4767 | |
| 4768 | int String::Write(uint16_t* buffer, |
| 4769 | int start, |
| 4770 | int length, |
| 4771 | int options) const { |
| 4772 | return WriteHelper(this, buffer, start, length, options); |
| 4773 | } |
| 4774 | |
| 4775 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4776 | bool v8::String::IsExternal() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4777 | i::Handle<i::String> str = Utils::OpenHandle(this); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4778 | EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4779 | return i::StringShape(*str).IsExternalTwoByte(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4783 | bool v8::String::IsExternalAscii() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4784 | i::Handle<i::String> str = Utils::OpenHandle(this); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4785 | return i::StringShape(*str).IsExternalAscii(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4789 | void v8::String::VerifyExternalStringResource( |
| 4790 | v8::String::ExternalStringResource* value) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4791 | i::Handle<i::String> str = Utils::OpenHandle(this); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4792 | const v8::String::ExternalStringResource* expected; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4793 | if (i::StringShape(*str).IsExternalTwoByte()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4794 | const void* resource = |
| 4795 | i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); |
| 4796 | expected = reinterpret_cast<const ExternalStringResource*>(resource); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4797 | } else { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4798 | expected = NULL; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4799 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4800 | CHECK_EQ(expected, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4801 | } |
| 4802 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4803 | void v8::String::VerifyExternalStringResourceBase( |
| 4804 | v8::String::ExternalStringResourceBase* value, Encoding encoding) const { |
| 4805 | i::Handle<i::String> str = Utils::OpenHandle(this); |
| 4806 | const v8::String::ExternalStringResourceBase* expected; |
| 4807 | Encoding expectedEncoding; |
| 4808 | if (i::StringShape(*str).IsExternalAscii()) { |
| 4809 | const void* resource = |
| 4810 | i::Handle<i::ExternalAsciiString>::cast(str)->resource(); |
| 4811 | expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); |
| 4812 | expectedEncoding = ASCII_ENCODING; |
| 4813 | } else if (i::StringShape(*str).IsExternalTwoByte()) { |
| 4814 | const void* resource = |
| 4815 | i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); |
| 4816 | expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); |
| 4817 | expectedEncoding = TWO_BYTE_ENCODING; |
| 4818 | } else { |
| 4819 | expected = NULL; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 4820 | expectedEncoding = str->IsOneByteRepresentation() ? ASCII_ENCODING |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4821 | : TWO_BYTE_ENCODING; |
| 4822 | } |
| 4823 | CHECK_EQ(expected, value); |
| 4824 | CHECK_EQ(expectedEncoding, encoding); |
| 4825 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4826 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4827 | const v8::String::ExternalAsciiStringResource* |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4828 | v8::String::GetExternalAsciiStringResource() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4829 | i::Handle<i::String> str = Utils::OpenHandle(this); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4830 | if (i::StringShape(*str).IsExternalAscii()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4831 | const void* resource = |
| 4832 | i::Handle<i::ExternalAsciiString>::cast(str)->resource(); |
| 4833 | return reinterpret_cast<const ExternalAsciiStringResource*>(resource); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4834 | } else { |
| 4835 | return NULL; |
| 4836 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4840 | Local<Value> Symbol::Name() const { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4841 | i::Handle<i::Symbol> sym = Utils::OpenHandle(this); |
| 4842 | i::Handle<i::Object> name(sym->name(), sym->GetIsolate()); |
| 4843 | return Utils::ToLocal(name); |
| 4844 | } |
| 4845 | |
| 4846 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 4847 | Local<Value> Private::Name() const { |
| 4848 | return reinterpret_cast<const Symbol*>(this)->Name(); |
| 4849 | } |
| 4850 | |
| 4851 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4852 | double Number::Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4853 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4854 | return obj->Number(); |
| 4855 | } |
| 4856 | |
| 4857 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4858 | bool Boolean::Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4859 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4860 | return obj->IsTrue(); |
| 4861 | } |
| 4862 | |
| 4863 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4864 | int64_t Integer::Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4865 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4866 | if (obj->IsSmi()) { |
| 4867 | return i::Smi::cast(*obj)->value(); |
| 4868 | } else { |
| 4869 | return static_cast<int64_t>(obj->Number()); |
| 4870 | } |
| 4871 | } |
| 4872 | |
| 4873 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4874 | int32_t Int32::Value() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4875 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4876 | if (obj->IsSmi()) { |
| 4877 | return i::Smi::cast(*obj)->value(); |
| 4878 | } else { |
| 4879 | return static_cast<int32_t>(obj->Number()); |
| 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4884 | uint32_t Uint32::Value() const { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4885 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 4886 | if (obj->IsSmi()) { |
| 4887 | return i::Smi::cast(*obj)->value(); |
| 4888 | } else { |
| 4889 | return static_cast<uint32_t>(obj->Number()); |
| 4890 | } |
| 4891 | } |
| 4892 | |
| 4893 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4894 | int v8::Object::InternalFieldCount() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4895 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4896 | return obj->GetInternalFieldCount(); |
| 4897 | } |
| 4898 | |
| 4899 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4900 | static bool InternalFieldOK(i::Handle<i::JSObject> obj, |
| 4901 | int index, |
| 4902 | const char* location) { |
machenbach@chromium.org | ae16103 | 2013-09-24 09:12:30 +0000 | [diff] [blame] | 4903 | return ApiCheck(index < obj->GetInternalFieldCount(), |
| 4904 | location, |
| 4905 | "Internal field out of bounds"); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | |
| 4909 | Local<Value> v8::Object::SlowGetInternalField(int index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4910 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4911 | const char* location = "v8::Object::GetInternalField()"; |
| 4912 | if (!InternalFieldOK(obj, index, location)) return Local<Value>(); |
| 4913 | i::Handle<i::Object> value(obj->GetInternalField(index), obj->GetIsolate()); |
| 4914 | return Utils::ToLocal(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 4918 | void v8::Object::SetInternalField(int index, v8::Handle<Value> value) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4919 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4920 | const char* location = "v8::Object::SetInternalField()"; |
| 4921 | if (!InternalFieldOK(obj, index, location)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4922 | i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 4923 | obj->SetInternalField(index, *val); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4924 | ASSERT_EQ(value, GetInternalField(index)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4928 | void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) { |
| 4929 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 4930 | const char* location = "v8::Object::GetAlignedPointerFromInternalField()"; |
| 4931 | if (!InternalFieldOK(obj, index, location)) return NULL; |
| 4932 | return DecodeSmiToAligned(obj->GetInternalField(index), location); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4933 | } |
| 4934 | |
| 4935 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4936 | void v8::Object::SetAlignedPointerInInternalField(int index, void* value) { |
| 4937 | i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 4938 | const char* location = "v8::Object::SetAlignedPointerInInternalField()"; |
| 4939 | if (!InternalFieldOK(obj, index, location)) return; |
| 4940 | obj->SetInternalField(index, EncodeAlignedAsSmi(value, location)); |
| 4941 | ASSERT_EQ(value, GetAlignedPointerFromInternalField(index)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 4945 | static void* ExternalValue(i::Object* obj) { |
| 4946 | // Obscure semantics for undefined, but somehow checked in our unit tests... |
| 4947 | if (obj->IsUndefined()) return NULL; |
| 4948 | i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0); |
| 4949 | return i::Foreign::cast(foreign)->foreign_address(); |
| 4950 | } |
| 4951 | |
| 4952 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4953 | // --- E n v i r o n m e n t --- |
| 4954 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4955 | |
machenbach@chromium.org | 90dca01 | 2013-11-22 10:04:21 +0000 | [diff] [blame] | 4956 | void v8::V8::InitializePlatform(Platform* platform) { |
| 4957 | #ifdef V8_USE_DEFAULT_PLATFORM |
| 4958 | FATAL("Can't override v8::Platform when using default implementation"); |
| 4959 | #else |
| 4960 | i::V8::InitializePlatform(platform); |
| 4961 | #endif |
| 4962 | } |
| 4963 | |
| 4964 | |
| 4965 | void v8::V8::ShutdownPlatform() { |
| 4966 | #ifdef V8_USE_DEFAULT_PLATFORM |
| 4967 | FATAL("Can't override v8::Platform when using default implementation"); |
| 4968 | #else |
| 4969 | i::V8::ShutdownPlatform(); |
| 4970 | #endif |
| 4971 | } |
| 4972 | |
| 4973 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4974 | bool v8::V8::Initialize() { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 4975 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4976 | if (isolate != NULL && isolate->IsInitialized()) { |
| 4977 | return true; |
| 4978 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4979 | return InitializeHelper(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4980 | } |
| 4981 | |
| 4982 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 4983 | void v8::V8::SetEntropySource(EntropySource entropy_source) { |
| 4984 | i::RandomNumberGenerator::SetEntropySource(entropy_source); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 4985 | } |
| 4986 | |
| 4987 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4988 | void v8::V8::SetReturnAddressLocationResolver( |
| 4989 | ReturnAddressLocationResolver return_address_resolver) { |
| 4990 | i::V8::SetReturnAddressLocationResolver(return_address_resolver); |
| 4991 | } |
| 4992 | |
| 4993 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4994 | bool v8::V8::SetFunctionEntryHook(Isolate* ext_isolate, |
| 4995 | FunctionEntryHook entry_hook) { |
| 4996 | ASSERT(ext_isolate != NULL); |
| 4997 | ASSERT(entry_hook != NULL); |
| 4998 | |
| 4999 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(ext_isolate); |
| 5000 | |
| 5001 | // The entry hook can only be set before the Isolate is initialized, as |
| 5002 | // otherwise the Isolate's code stubs generated at initialization won't |
| 5003 | // contain entry hooks. |
| 5004 | if (isolate->IsInitialized()) |
| 5005 | return false; |
| 5006 | |
| 5007 | // Setting an entry hook is a one-way operation, once set, it cannot be |
| 5008 | // changed or unset. |
| 5009 | if (isolate->function_entry_hook() != NULL) |
| 5010 | return false; |
| 5011 | |
| 5012 | isolate->set_function_entry_hook(entry_hook); |
| 5013 | return true; |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5017 | void v8::V8::SetJitCodeEventHandler( |
| 5018 | JitCodeEventOptions options, JitCodeEventHandler event_handler) { |
| 5019 | i::Isolate* isolate = i::Isolate::Current(); |
| 5020 | // Ensure that logging is initialized for our isolate. |
| 5021 | isolate->InitializeLoggingAndCounters(); |
| 5022 | isolate->logger()->SetCodeEventHandler(options, event_handler); |
| 5023 | } |
| 5024 | |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 5025 | void v8::V8::SetArrayBufferAllocator( |
| 5026 | ArrayBuffer::Allocator* allocator) { |
| 5027 | if (!ApiCheck(i::V8::ArrayBufferAllocator() == NULL, |
| 5028 | "v8::V8::SetArrayBufferAllocator", |
| 5029 | "ArrayBufferAllocator might only be set once")) |
| 5030 | return; |
| 5031 | i::V8::SetArrayBufferAllocator(allocator); |
| 5032 | } |
| 5033 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 5034 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5035 | bool v8::V8::Dispose() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5036 | i::Isolate* isolate = i::Isolate::Current(); |
| 5037 | if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(), |
| 5038 | "v8::V8::Dispose()", |
| 5039 | "Use v8::Isolate::Dispose() for a non-default isolate.")) { |
| 5040 | return false; |
| 5041 | } |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5042 | i::V8::TearDown(); |
| 5043 | return true; |
| 5044 | } |
| 5045 | |
| 5046 | |
ager@chromium.org | 01fe7df | 2010-11-10 11:59:11 +0000 | [diff] [blame] | 5047 | HeapStatistics::HeapStatistics(): total_heap_size_(0), |
| 5048 | total_heap_size_executable_(0), |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 5049 | total_physical_size_(0), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 5050 | used_heap_size_(0), |
| 5051 | heap_size_limit_(0) { } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5052 | |
| 5053 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5054 | void v8::V8::VisitExternalResources(ExternalResourceVisitor* visitor) { |
| 5055 | i::Isolate* isolate = i::Isolate::Current(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5056 | isolate->heap()->VisitExternalResources(visitor); |
| 5057 | } |
| 5058 | |
| 5059 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5060 | class VisitorAdapter : public i::ObjectVisitor { |
| 5061 | public: |
| 5062 | explicit VisitorAdapter(PersistentHandleVisitor* visitor) |
| 5063 | : visitor_(visitor) {} |
| 5064 | virtual void VisitPointers(i::Object** start, i::Object** end) { |
| 5065 | UNREACHABLE(); |
| 5066 | } |
| 5067 | virtual void VisitEmbedderReference(i::Object** p, uint16_t class_id) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 5068 | Value* value = ToApi<Value>(i::Handle<i::Object>(p)); |
| 5069 | visitor_->VisitPersistentHandle( |
| 5070 | reinterpret_cast<Persistent<Value>*>(&value), class_id); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5071 | } |
| 5072 | private: |
| 5073 | PersistentHandleVisitor* visitor_; |
| 5074 | }; |
| 5075 | |
| 5076 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5077 | void v8::V8::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) { |
| 5078 | i::Isolate* isolate = i::Isolate::Current(); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 5079 | i::DisallowHeapAllocation no_allocation; |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5080 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5081 | VisitorAdapter visitor_adapter(visitor); |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 5082 | isolate->global_handles()->IterateAllRootsWithClassIds(&visitor_adapter); |
| 5083 | } |
| 5084 | |
| 5085 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5086 | void v8::V8::VisitHandlesForPartialDependence( |
| 5087 | Isolate* exported_isolate, PersistentHandleVisitor* visitor) { |
| 5088 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(exported_isolate); |
| 5089 | ASSERT(isolate == i::Isolate::Current()); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 5090 | i::DisallowHeapAllocation no_allocation; |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 5091 | |
| 5092 | VisitorAdapter visitor_adapter(visitor); |
| 5093 | isolate->global_handles()->IterateAllRootsInNewSpaceWithClassIds( |
| 5094 | &visitor_adapter); |
| 5095 | } |
| 5096 | |
| 5097 | |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 5098 | bool v8::V8::IdleNotification(int hint) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5099 | // Returning true tells the caller that it need not |
| 5100 | // continue to call IdleNotification. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5101 | i::Isolate* isolate = i::Isolate::Current(); |
| 5102 | if (isolate == NULL || !isolate->IsInitialized()) return true; |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 5103 | if (!i::FLAG_use_idle_notification) return true; |
| 5104 | return isolate->heap()->IdleNotification(hint); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 5105 | } |
| 5106 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5107 | |
| 5108 | void v8::V8::LowMemoryNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5109 | i::Isolate* isolate = i::Isolate::Current(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5110 | if (isolate == NULL || !isolate->IsInitialized()) return; |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 5111 | isolate->heap()->CollectAllAvailableGarbage("low memory notification"); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5115 | int v8::V8::ContextDisposedNotification() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5116 | i::Isolate* isolate = i::Isolate::Current(); |
| 5117 | if (!isolate->IsInitialized()) return 0; |
| 5118 | return isolate->heap()->NotifyContextDisposed(); |
kasperl@chromium.org | 8b2bb26 | 2010-03-01 09:46:28 +0000 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 5122 | bool v8::V8::InitializeICU() { |
| 5123 | return i::InitializeICU(); |
| 5124 | } |
| 5125 | |
| 5126 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 5127 | const char* v8::V8::GetVersion() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5128 | return i::Version::GetVersion(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 5129 | } |
| 5130 | |
| 5131 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5132 | static i::Handle<i::Context> CreateEnvironment( |
| 5133 | i::Isolate* isolate, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5134 | v8::ExtensionConfiguration* extensions, |
| 5135 | v8::Handle<ObjectTemplate> global_template, |
| 5136 | v8::Handle<Value> global_object) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5137 | i::Handle<i::Context> env; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5138 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5139 | // Enter V8 via an ENTER_V8 scope. |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5140 | { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5141 | ENTER_V8(isolate); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5142 | v8::Handle<ObjectTemplate> proxy_template = global_template; |
| 5143 | i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
| 5144 | i::Handle<i::FunctionTemplateInfo> global_constructor; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 5145 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5146 | if (!global_template.IsEmpty()) { |
| 5147 | // Make sure that the global_template has a constructor. |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 5148 | global_constructor = EnsureConstructor(isolate, *global_template); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5149 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5150 | // Create a fresh template for the global proxy object. |
| 5151 | proxy_template = ObjectTemplate::New(); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 5152 | proxy_constructor = EnsureConstructor(isolate, *proxy_template); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5153 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5154 | // Set the global template to be the prototype template of |
| 5155 | // global proxy template. |
| 5156 | proxy_constructor->set_prototype_template( |
| 5157 | *Utils::OpenHandle(*global_template)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5158 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5159 | // Migrate security handlers from global_template to |
| 5160 | // proxy_template. Temporarily removing access check |
| 5161 | // information from the global template. |
| 5162 | if (!global_constructor->access_check_info()->IsUndefined()) { |
| 5163 | proxy_constructor->set_access_check_info( |
| 5164 | global_constructor->access_check_info()); |
| 5165 | proxy_constructor->set_needs_access_check( |
| 5166 | global_constructor->needs_access_check()); |
| 5167 | global_constructor->set_needs_access_check(false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5168 | global_constructor->set_access_check_info( |
| 5169 | isolate->heap()->undefined_value()); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5170 | } |
| 5171 | } |
| 5172 | |
| 5173 | // Create the environment. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5174 | env = isolate->bootstrapper()->CreateEnvironment( |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 5175 | Utils::OpenHandle(*global_object, true), |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5176 | proxy_template, |
| 5177 | extensions); |
| 5178 | |
| 5179 | // Restore the access check info on the global template. |
| 5180 | if (!global_template.IsEmpty()) { |
| 5181 | ASSERT(!global_constructor.is_null()); |
| 5182 | ASSERT(!proxy_constructor.is_null()); |
| 5183 | global_constructor->set_access_check_info( |
| 5184 | proxy_constructor->access_check_info()); |
| 5185 | global_constructor->set_needs_access_check( |
| 5186 | proxy_constructor->needs_access_check()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5187 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5188 | } |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5189 | // Leave V8. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 5190 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5191 | return env; |
| 5192 | } |
| 5193 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5194 | Local<Context> v8::Context::New( |
| 5195 | v8::Isolate* external_isolate, |
| 5196 | v8::ExtensionConfiguration* extensions, |
| 5197 | v8::Handle<ObjectTemplate> global_template, |
| 5198 | v8::Handle<Value> global_object) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5199 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
| 5200 | EnsureInitializedForIsolate(isolate, "v8::Context::New()"); |
| 5201 | LOG_API(isolate, "Context::New"); |
| 5202 | ON_BAILOUT(isolate, "v8::Context::New()", return Local<Context>()); |
| 5203 | i::HandleScope scope(isolate); |
| 5204 | i::Handle<i::Context> env = |
| 5205 | CreateEnvironment(isolate, extensions, global_template, global_object); |
| 5206 | if (env.is_null()) return Local<Context>(); |
| 5207 | return Utils::ToLocal(scope.CloseAndEscape(env)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | |
| 5211 | void v8::Context::SetSecurityToken(Handle<Value> token) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5212 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5213 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5214 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 5215 | i::Handle<i::Object> token_handle = Utils::OpenHandle(*token); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5216 | env->set_security_token(*token_handle); |
| 5217 | } |
| 5218 | |
| 5219 | |
| 5220 | void v8::Context::UseDefaultSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5221 | i::Isolate* isolate = i::Isolate::Current(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5222 | ENTER_V8(isolate); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5223 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 5224 | env->set_security_token(env->global_object()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | |
| 5228 | Handle<Value> v8::Context::GetSecurityToken() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5229 | i::Isolate* isolate = i::Isolate::Current(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5230 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5231 | i::Object* security_token = env->security_token(); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5232 | i::Handle<i::Object> token_handle(security_token, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5233 | return Utils::ToLocal(token_handle); |
| 5234 | } |
| 5235 | |
| 5236 | |
| 5237 | bool Context::HasOutOfMemoryException() { |
| 5238 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 5239 | return env->has_out_of_memory(); |
| 5240 | } |
| 5241 | |
| 5242 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5243 | v8::Isolate* Context::GetIsolate() { |
| 5244 | i::Handle<i::Context> env = Utils::OpenHandle(this); |
| 5245 | return reinterpret_cast<Isolate*>(env->GetIsolate()); |
| 5246 | } |
| 5247 | |
| 5248 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5249 | v8::Local<v8::Object> Context::Global() { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5250 | i::Handle<i::Context> context = Utils::OpenHandle(this); |
| 5251 | i::Isolate* isolate = context->GetIsolate(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5252 | i::Handle<i::Object> global(context->global_proxy(), isolate); |
jkummerow@chromium.org | 113035e | 2013-12-13 15:13:40 +0000 | [diff] [blame] | 5253 | // TODO(dcarney): This should always return the global proxy |
| 5254 | // but can't presently as calls to GetProtoype will return the wrong result. |
| 5255 | if (i::Handle<i::JSGlobalProxy>::cast( |
| 5256 | global)->IsDetachedFrom(context->global_object())) { |
| 5257 | global = i::Handle<i::Object>(context->global_object(), isolate); |
| 5258 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5259 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(global)); |
| 5260 | } |
| 5261 | |
| 5262 | |
| 5263 | void Context::DetachGlobal() { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5264 | i::Handle<i::Context> context = Utils::OpenHandle(this); |
| 5265 | i::Isolate* isolate = context->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5266 | ENTER_V8(isolate); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5267 | isolate->bootstrapper()->DetachGlobal(context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5268 | } |
| 5269 | |
| 5270 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5271 | void Context::AllowCodeGenerationFromStrings(bool allow) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5272 | i::Handle<i::Context> context = Utils::OpenHandle(this); |
| 5273 | i::Isolate* isolate = context->GetIsolate(); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5274 | ENTER_V8(isolate); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 5275 | context->set_allow_code_gen_from_strings( |
| 5276 | allow ? isolate->heap()->true_value() : isolate->heap()->false_value()); |
| 5277 | } |
| 5278 | |
| 5279 | |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 5280 | bool Context::IsCodeGenerationFromStringsAllowed() { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5281 | i::Handle<i::Context> context = Utils::OpenHandle(this); |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 5282 | return !context->allow_code_gen_from_strings()->IsFalse(); |
| 5283 | } |
| 5284 | |
| 5285 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5286 | void Context::SetErrorMessageForCodeGenerationFromStrings( |
| 5287 | Handle<String> error) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5288 | i::Handle<i::Context> context = Utils::OpenHandle(this); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5289 | i::Handle<i::String> error_handle = Utils::OpenHandle(*error); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 5290 | context->set_error_message_for_code_gen_from_strings(*error_handle); |
| 5291 | } |
| 5292 | |
| 5293 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5294 | Local<v8::Object> ObjectTemplate::NewInstance() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5295 | i::Isolate* isolate = i::Isolate::Current(); |
| 5296 | ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()", |
| 5297 | return Local<v8::Object>()); |
| 5298 | LOG_API(isolate, "ObjectTemplate::NewInstance"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5299 | ENTER_V8(isolate); |
| 5300 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5301 | i::Handle<i::Object> obj = |
| 5302 | i::Execution::InstantiateObject(Utils::OpenHandle(this), |
| 5303 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5304 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5305 | return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj)); |
| 5306 | } |
| 5307 | |
| 5308 | |
| 5309 | Local<v8::Function> FunctionTemplate::GetFunction() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5310 | i::Isolate* isolate = i::Isolate::Current(); |
| 5311 | ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5312 | return Local<v8::Function>()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5313 | LOG_API(isolate, "FunctionTemplate::GetFunction"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5314 | ENTER_V8(isolate); |
| 5315 | EXCEPTION_PREAMBLE(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5316 | i::Handle<i::Object> obj = |
| 5317 | i::Execution::InstantiateFunction(Utils::OpenHandle(this), |
| 5318 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5319 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Function>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5320 | return Utils::ToLocal(i::Handle<i::JSFunction>::cast(obj)); |
| 5321 | } |
| 5322 | |
| 5323 | |
| 5324 | bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5325 | ON_BAILOUT(i::Isolate::Current(), "v8::FunctionTemplate::HasInstanceOf()", |
| 5326 | return false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5327 | i::Object* obj = *Utils::OpenHandle(*value); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 5328 | return Utils::OpenHandle(this)->IsTemplateFor(obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 5332 | Local<External> v8::External::New(Isolate* isolate, void* value) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5333 | STATIC_ASSERT(sizeof(value) == sizeof(i::Address)); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 5334 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5335 | EnsureInitializedForIsolate(i_isolate, "v8::External::New()"); |
| 5336 | LOG_API(i_isolate, "External::New"); |
| 5337 | ENTER_V8(i_isolate); |
| 5338 | i::Handle<i::JSObject> external = i_isolate->factory()->NewExternal(value); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5339 | return Utils::ExternalToLocal(external); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | |
| 5343 | void* External::Value() const { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 5344 | return ExternalValue(*Utils::OpenHandle(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5348 | // anonymous namespace for string creation helper functions |
| 5349 | namespace { |
| 5350 | |
| 5351 | inline int StringLength(const char* string) { |
| 5352 | return i::StrLength(string); |
| 5353 | } |
| 5354 | |
| 5355 | |
| 5356 | inline int StringLength(const uint8_t* string) { |
| 5357 | return i::StrLength(reinterpret_cast<const char*>(string)); |
| 5358 | } |
| 5359 | |
| 5360 | |
| 5361 | inline int StringLength(const uint16_t* string) { |
| 5362 | int length = 0; |
| 5363 | while (string[length] != '\0') |
| 5364 | length++; |
| 5365 | return length; |
| 5366 | } |
| 5367 | |
| 5368 | |
| 5369 | inline i::Handle<i::String> NewString(i::Factory* factory, |
| 5370 | String::NewStringType type, |
| 5371 | i::Vector<const char> string) { |
| 5372 | if (type ==String::kInternalizedString) { |
| 5373 | return factory->InternalizeUtf8String(string); |
| 5374 | } |
| 5375 | return factory->NewStringFromUtf8(string); |
| 5376 | } |
| 5377 | |
| 5378 | |
| 5379 | inline i::Handle<i::String> NewString(i::Factory* factory, |
| 5380 | String::NewStringType type, |
| 5381 | i::Vector<const uint8_t> string) { |
| 5382 | if (type == String::kInternalizedString) { |
| 5383 | return factory->InternalizeOneByteString(string); |
| 5384 | } |
| 5385 | return factory->NewStringFromOneByte(string); |
| 5386 | } |
| 5387 | |
| 5388 | |
| 5389 | inline i::Handle<i::String> NewString(i::Factory* factory, |
| 5390 | String::NewStringType type, |
| 5391 | i::Vector<const uint16_t> string) { |
| 5392 | if (type == String::kInternalizedString) { |
| 5393 | return factory->InternalizeTwoByteString(string); |
| 5394 | } |
| 5395 | return factory->NewStringFromTwoByte(string); |
| 5396 | } |
| 5397 | |
| 5398 | |
| 5399 | template<typename Char> |
| 5400 | inline Local<String> NewString(Isolate* v8_isolate, |
| 5401 | const char* location, |
| 5402 | const char* env, |
| 5403 | const Char* data, |
| 5404 | String::NewStringType type, |
| 5405 | int length) { |
| 5406 | i::Isolate* isolate = reinterpret_cast<internal::Isolate*>(v8_isolate); |
| 5407 | EnsureInitializedForIsolate(isolate, location); |
| 5408 | LOG_API(isolate, env); |
| 5409 | if (length == 0 && type != String::kUndetectableString) { |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 5410 | return String::Empty(v8_isolate); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5411 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5412 | ENTER_V8(isolate); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5413 | if (length == -1) length = StringLength(data); |
| 5414 | i::Handle<i::String> result = NewString( |
| 5415 | isolate->factory(), type, i::Vector<const Char>(data, length)); |
| 5416 | if (type == String::kUndetectableString) { |
| 5417 | result->MarkAsUndetectable(); |
| 5418 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5419 | return Utils::ToLocal(result); |
| 5420 | } |
| 5421 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5422 | } // anonymous namespace |
| 5423 | |
| 5424 | |
| 5425 | Local<String> String::NewFromUtf8(Isolate* isolate, |
| 5426 | const char* data, |
| 5427 | NewStringType type, |
| 5428 | int length) { |
| 5429 | return NewString(isolate, |
| 5430 | "v8::String::NewFromUtf8()", |
| 5431 | "String::NewFromUtf8", |
| 5432 | data, |
| 5433 | type, |
| 5434 | length); |
| 5435 | } |
| 5436 | |
| 5437 | |
| 5438 | Local<String> String::NewFromOneByte(Isolate* isolate, |
| 5439 | const uint8_t* data, |
| 5440 | NewStringType type, |
| 5441 | int length) { |
| 5442 | return NewString(isolate, |
| 5443 | "v8::String::NewFromOneByte()", |
| 5444 | "String::NewFromOneByte", |
| 5445 | data, |
| 5446 | type, |
| 5447 | length); |
| 5448 | } |
| 5449 | |
| 5450 | |
| 5451 | Local<String> String::NewFromTwoByte(Isolate* isolate, |
| 5452 | const uint16_t* data, |
| 5453 | NewStringType type, |
| 5454 | int length) { |
| 5455 | return NewString(isolate, |
| 5456 | "v8::String::NewFromTwoByte()", |
| 5457 | "String::NewFromTwoByte", |
| 5458 | data, |
| 5459 | type, |
| 5460 | length); |
| 5461 | } |
| 5462 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5463 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5464 | 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] | 5465 | i::Handle<i::String> left_string = Utils::OpenHandle(*left); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5466 | i::Isolate* isolate = left_string->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5467 | EnsureInitializedForIsolate(isolate, "v8::String::New()"); |
| 5468 | LOG_API(isolate, "String::New(char)"); |
| 5469 | ENTER_V8(isolate); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5470 | i::Handle<i::String> right_string = Utils::OpenHandle(*right); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5471 | i::Handle<i::String> result = isolate->factory()->NewConsString(left_string, |
| 5472 | right_string); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5473 | return Utils::ToLocal(result); |
| 5474 | } |
| 5475 | |
| 5476 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5477 | i::Handle<i::String> NewExternalStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5478 | v8::String::ExternalStringResource* resource) { |
| 5479 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5480 | isolate->factory()->NewExternalStringFromTwoByte(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5481 | return result; |
| 5482 | } |
| 5483 | |
| 5484 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5485 | i::Handle<i::String> NewExternalAsciiStringHandle(i::Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5486 | v8::String::ExternalAsciiStringResource* resource) { |
| 5487 | i::Handle<i::String> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5488 | isolate->factory()->NewExternalStringFromAscii(resource); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5489 | return result; |
| 5490 | } |
| 5491 | |
| 5492 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5493 | bool RedirectToExternalString(i::Isolate* isolate, |
| 5494 | i::Handle<i::String> parent, |
| 5495 | i::Handle<i::String> external) { |
| 5496 | if (parent->IsConsString()) { |
| 5497 | i::Handle<i::ConsString> cons = i::Handle<i::ConsString>::cast(parent); |
| 5498 | cons->set_first(*external); |
| 5499 | cons->set_second(isolate->heap()->empty_string()); |
| 5500 | } else { |
| 5501 | ASSERT(parent->IsSlicedString()); |
| 5502 | i::Handle<i::SlicedString> slice = i::Handle<i::SlicedString>::cast(parent); |
| 5503 | slice->set_parent(*external); |
| 5504 | slice->set_offset(0); |
| 5505 | } |
| 5506 | return true; |
| 5507 | } |
| 5508 | |
| 5509 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5510 | Local<String> v8::String::NewExternal( |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5511 | Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5512 | v8::String::ExternalStringResource* resource) { |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5513 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5514 | EnsureInitializedForIsolate(i_isolate, "v8::String::NewExternal()"); |
| 5515 | LOG_API(i_isolate, "String::NewExternal"); |
| 5516 | ENTER_V8(i_isolate); |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 5517 | CHECK(resource && resource->data()); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5518 | i::Handle<i::String> result = NewExternalStringHandle(i_isolate, resource); |
| 5519 | i_isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5520 | return Utils::ToLocal(result); |
| 5521 | } |
| 5522 | |
| 5523 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 5524 | bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5525 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 5526 | i::Isolate* isolate = obj->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5527 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 5528 | return false; // Already an external string. |
| 5529 | } |
| 5530 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5531 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 5532 | return false; |
| 5533 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5534 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 5535 | return false; |
| 5536 | } |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 5537 | CHECK(resource && resource->data()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5538 | |
| 5539 | bool result; |
| 5540 | i::Handle<i::String> external; |
| 5541 | if (isolate->heap()->old_pointer_space()->Contains(*obj)) { |
| 5542 | // We do not allow external strings in the old pointer space. Instead of |
| 5543 | // converting the string in-place, we keep the cons/sliced string and |
| 5544 | // point it to a newly-allocated external string. |
| 5545 | external = NewExternalStringHandle(isolate, resource); |
| 5546 | result = RedirectToExternalString(isolate, obj, external); |
| 5547 | } else { |
| 5548 | result = obj->MakeExternal(resource); |
| 5549 | external = obj; |
| 5550 | } |
| 5551 | |
jkummerow@chromium.org | 113035e | 2013-12-13 15:13:40 +0000 | [diff] [blame] | 5552 | if (result) { |
| 5553 | ASSERT(external->IsExternalString()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5554 | isolate->heap()->external_string_table()->AddString(*external); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 5555 | } |
| 5556 | return result; |
| 5557 | } |
| 5558 | |
| 5559 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5560 | Local<String> v8::String::NewExternal( |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5561 | Isolate* isolate, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5562 | v8::String::ExternalAsciiStringResource* resource) { |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5563 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5564 | EnsureInitializedForIsolate(i_isolate, "v8::String::NewExternal()"); |
| 5565 | LOG_API(i_isolate, "String::NewExternal"); |
| 5566 | ENTER_V8(i_isolate); |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 5567 | CHECK(resource && resource->data()); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5568 | i::Handle<i::String> result = |
| 5569 | NewExternalAsciiStringHandle(i_isolate, resource); |
| 5570 | i_isolate->heap()->external_string_table()->AddString(*result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5571 | return Utils::ToLocal(result); |
| 5572 | } |
| 5573 | |
| 5574 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 5575 | bool v8::String::MakeExternal( |
| 5576 | v8::String::ExternalAsciiStringResource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5577 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 5578 | i::Isolate* isolate = obj->GetIsolate(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5579 | if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 5580 | return false; // Already an external string. |
| 5581 | } |
| 5582 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5583 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 5584 | return false; |
| 5585 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5586 | if (isolate->heap()->IsInGCPostProcessing()) { |
| 5587 | return false; |
| 5588 | } |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 5589 | CHECK(resource && resource->data()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5590 | |
| 5591 | bool result; |
| 5592 | i::Handle<i::String> external; |
| 5593 | if (isolate->heap()->old_pointer_space()->Contains(*obj)) { |
| 5594 | // We do not allow external strings in the old pointer space. Instead of |
| 5595 | // converting the string in-place, we keep the cons/sliced string and |
| 5596 | // point it to a newly-allocated external string. |
| 5597 | external = NewExternalAsciiStringHandle(isolate, resource); |
| 5598 | result = RedirectToExternalString(isolate, obj, external); |
| 5599 | } else { |
| 5600 | result = obj->MakeExternal(resource); |
| 5601 | external = obj; |
| 5602 | } |
| 5603 | |
jkummerow@chromium.org | 113035e | 2013-12-13 15:13:40 +0000 | [diff] [blame] | 5604 | if (result) { |
| 5605 | ASSERT(external->IsExternalString()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5606 | isolate->heap()->external_string_table()->AddString(*external); |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 5607 | } |
| 5608 | return result; |
| 5609 | } |
| 5610 | |
| 5611 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5612 | bool v8::String::CanMakeExternal() { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5613 | if (!internal::FLAG_clever_optimizations) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5614 | i::Handle<i::String> obj = Utils::OpenHandle(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5615 | i::Isolate* isolate = obj->GetIsolate(); |
jkummerow@chromium.org | 32aa03c | 2013-10-01 08:21:50 +0000 | [diff] [blame] | 5616 | |
| 5617 | // TODO(yangguo): Externalizing sliced/cons strings allocates. |
| 5618 | // This rule can be removed when all code that can |
| 5619 | // trigger an access check is handlified and therefore GC safe. |
| 5620 | if (isolate->heap()->old_pointer_space()->Contains(*obj)) return false; |
| 5621 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5622 | if (isolate->string_tracker()->IsFreshUnusedString(obj)) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5623 | int size = obj->Size(); // Byte size of the original string. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5624 | if (size < i::ExternalString::kShortSize) return false; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 5625 | i::StringShape shape(*obj); |
| 5626 | return !shape.IsExternal(); |
| 5627 | } |
| 5628 | |
| 5629 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5630 | Local<v8::Object> v8::Object::New(Isolate* isolate) { |
| 5631 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5632 | EnsureInitializedForIsolate(i_isolate, "v8::Object::New()"); |
| 5633 | LOG_API(i_isolate, "Object::New"); |
| 5634 | ENTER_V8(i_isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5635 | i::Handle<i::JSObject> obj = |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5636 | i_isolate->factory()->NewJSObject(i_isolate->object_function()); |
| 5637 | return Utils::ToLocal(obj); |
| 5638 | } |
| 5639 | |
| 5640 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5641 | Local<v8::Value> v8::NumberObject::New(Isolate* isolate, double value) { |
| 5642 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5643 | EnsureInitializedForIsolate(i_isolate, "v8::NumberObject::New()"); |
| 5644 | LOG_API(i_isolate, "NumberObject::New"); |
| 5645 | ENTER_V8(i_isolate); |
| 5646 | i::Handle<i::Object> number = i_isolate->factory()->NewNumber(value); |
| 5647 | i::Handle<i::Object> obj = i_isolate->factory()->ToObject(number); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5648 | return Utils::ToLocal(obj); |
| 5649 | } |
| 5650 | |
| 5651 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5652 | double v8::NumberObject::ValueOf() const { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5653 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5654 | LOG_API(isolate, "NumberObject::NumberValue"); |
| 5655 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5656 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 5657 | return jsvalue->value()->Number(); |
| 5658 | } |
| 5659 | |
| 5660 | |
| 5661 | Local<v8::Value> v8::BooleanObject::New(bool value) { |
| 5662 | i::Isolate* isolate = i::Isolate::Current(); |
| 5663 | EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()"); |
| 5664 | LOG_API(isolate, "BooleanObject::New"); |
| 5665 | ENTER_V8(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 5666 | i::Handle<i::Object> boolean(value |
| 5667 | ? isolate->heap()->true_value() |
| 5668 | : isolate->heap()->false_value(), |
| 5669 | isolate); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5670 | i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean); |
| 5671 | return Utils::ToLocal(obj); |
| 5672 | } |
| 5673 | |
| 5674 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5675 | bool v8::BooleanObject::ValueOf() const { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5676 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5677 | LOG_API(isolate, "BooleanObject::BooleanValue"); |
| 5678 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5679 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 5680 | return jsvalue->value()->IsTrue(); |
| 5681 | } |
| 5682 | |
| 5683 | |
| 5684 | Local<v8::Value> v8::StringObject::New(Handle<String> value) { |
| 5685 | i::Isolate* isolate = i::Isolate::Current(); |
| 5686 | EnsureInitializedForIsolate(isolate, "v8::StringObject::New()"); |
| 5687 | LOG_API(isolate, "StringObject::New"); |
| 5688 | ENTER_V8(isolate); |
| 5689 | i::Handle<i::Object> obj = |
| 5690 | isolate->factory()->ToObject(Utils::OpenHandle(*value)); |
| 5691 | return Utils::ToLocal(obj); |
| 5692 | } |
| 5693 | |
| 5694 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5695 | Local<v8::String> v8::StringObject::ValueOf() const { |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5696 | i::Isolate* isolate = i::Isolate::Current(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 5697 | LOG_API(isolate, "StringObject::StringValue"); |
| 5698 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5699 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 5700 | return Utils::ToLocal( |
| 5701 | i::Handle<i::String>(i::String::cast(jsvalue->value()))); |
| 5702 | } |
| 5703 | |
| 5704 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5705 | Local<v8::Value> v8::SymbolObject::New(Isolate* isolate, Handle<Symbol> value) { |
| 5706 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5707 | EnsureInitializedForIsolate(i_isolate, "v8::SymbolObject::New()"); |
| 5708 | LOG_API(i_isolate, "SymbolObject::New"); |
| 5709 | ENTER_V8(i_isolate); |
| 5710 | i::Handle<i::Object> obj = |
| 5711 | i_isolate->factory()->ToObject(Utils::OpenHandle(*value)); |
| 5712 | return Utils::ToLocal(obj); |
| 5713 | } |
| 5714 | |
| 5715 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5716 | Local<v8::Symbol> v8::SymbolObject::ValueOf() const { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5717 | i::Isolate* isolate = i::Isolate::Current(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5718 | LOG_API(isolate, "SymbolObject::SymbolValue"); |
| 5719 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 5720 | i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 5721 | return Utils::ToLocal( |
| 5722 | i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value()))); |
| 5723 | } |
| 5724 | |
| 5725 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5726 | Local<v8::Value> v8::Date::New(Isolate* isolate, double time) { |
| 5727 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5728 | EnsureInitializedForIsolate(i_isolate, "v8::Date::New()"); |
| 5729 | LOG_API(i_isolate, "Date::New"); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 5730 | if (std::isnan(time)) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5731 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 5732 | time = i::OS::nan_value(); |
| 5733 | } |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5734 | ENTER_V8(i_isolate); |
| 5735 | EXCEPTION_PREAMBLE(i_isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5736 | i::Handle<i::Object> obj = |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5737 | i::Execution::NewDate(i_isolate, time, &has_pending_exception); |
| 5738 | EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::Value>()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5739 | return Utils::ToLocal(obj); |
| 5740 | } |
| 5741 | |
| 5742 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 5743 | double v8::Date::ValueOf() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5744 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5745 | LOG_API(isolate, "Date::NumberValue"); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5746 | i::Handle<i::Object> obj = Utils::OpenHandle(this); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5747 | i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj); |
| 5748 | return jsdate->value()->Number(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5749 | } |
| 5750 | |
| 5751 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5752 | void v8::Date::DateTimeConfigurationChangeNotification(Isolate* isolate) { |
| 5753 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5754 | ON_BAILOUT(i_isolate, "v8::Date::DateTimeConfigurationChangeNotification()", |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5755 | return); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5756 | LOG_API(i_isolate, "Date::DateTimeConfigurationChangeNotification"); |
| 5757 | ENTER_V8(i_isolate); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5758 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5759 | i_isolate->date_cache()->ResetDateCache(); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5760 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5761 | i::HandleScope scope(i_isolate); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 5762 | // Get the function ResetDateCache (defined in date.js). |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5763 | i::Handle<i::String> func_name_str = |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5764 | i_isolate->factory()->InternalizeOneByteString( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5765 | STATIC_ASCII_VECTOR("ResetDateCache")); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5766 | i::MaybeObject* result = |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5767 | i_isolate->js_builtins_object()->GetProperty(*func_name_str); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5768 | i::Object* object_func; |
| 5769 | if (!result->ToObject(&object_func)) { |
| 5770 | return; |
| 5771 | } |
| 5772 | |
| 5773 | if (object_func->IsJSFunction()) { |
| 5774 | i::Handle<i::JSFunction> func = |
| 5775 | i::Handle<i::JSFunction>(i::JSFunction::cast(object_func)); |
| 5776 | |
| 5777 | // Call ResetDateCache(0 but expect no exceptions: |
| 5778 | bool caught_exception = false; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 5779 | i::Execution::TryCall(func, |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5780 | i_isolate->js_builtins_object(), |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 5781 | 0, |
| 5782 | NULL, |
| 5783 | &caught_exception); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5784 | } |
| 5785 | } |
| 5786 | |
| 5787 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5788 | static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5789 | i::Isolate* isolate = i::Isolate::Current(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5790 | uint8_t flags_buf[3]; |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5791 | int num_flags = 0; |
| 5792 | if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; |
| 5793 | if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; |
| 5794 | if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; |
| 5795 | ASSERT(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf))); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5796 | return isolate->factory()->InternalizeOneByteString( |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5797 | i::Vector<const uint8_t>(flags_buf, num_flags)); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | |
| 5801 | Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, |
| 5802 | Flags flags) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5803 | i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5804 | EnsureInitializedForIsolate(isolate, "v8::RegExp::New()"); |
| 5805 | LOG_API(isolate, "RegExp::New"); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5806 | ENTER_V8(isolate); |
| 5807 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5808 | i::Handle<i::JSRegExp> obj = i::Execution::NewJSRegExp( |
| 5809 | Utils::OpenHandle(*pattern), |
| 5810 | RegExpFlagsToString(flags), |
| 5811 | &has_pending_exception); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5812 | EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::RegExp>()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5813 | return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj)); |
| 5814 | } |
| 5815 | |
| 5816 | |
| 5817 | Local<v8::String> v8::RegExp::GetSource() const { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5818 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 5819 | return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); |
| 5820 | } |
| 5821 | |
| 5822 | |
| 5823 | // Assert that the static flags cast in GetFlags is valid. |
| 5824 | #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \ |
| 5825 | STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \ |
| 5826 | static_cast<int>(i::JSRegExp::internal_flag)) |
| 5827 | REGEXP_FLAG_ASSERT_EQ(kNone, NONE); |
| 5828 | REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL); |
| 5829 | REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE); |
| 5830 | REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE); |
| 5831 | #undef REGEXP_FLAG_ASSERT_EQ |
| 5832 | |
| 5833 | v8::RegExp::Flags v8::RegExp::GetFlags() const { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5834 | i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); |
| 5835 | return static_cast<RegExp::Flags>(obj->GetFlags().value()); |
| 5836 | } |
| 5837 | |
| 5838 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5839 | Local<v8::Array> v8::Array::New(Isolate* isolate, int length) { |
| 5840 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5841 | EnsureInitializedForIsolate(i_isolate, "v8::Array::New()"); |
| 5842 | LOG_API(i_isolate, "Array::New"); |
| 5843 | ENTER_V8(i_isolate); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5844 | int real_length = length > 0 ? length : 0; |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5845 | i::Handle<i::JSArray> obj = i_isolate->factory()->NewJSArray(real_length); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 5846 | i::Handle<i::Object> length_obj = |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5847 | i_isolate->factory()->NewNumberFromInt(real_length); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 5848 | obj->set_length(*length_obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5849 | return Utils::ToLocal(obj); |
| 5850 | } |
| 5851 | |
| 5852 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5853 | uint32_t v8::Array::Length() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5854 | i::Handle<i::JSArray> obj = Utils::OpenHandle(this); |
| 5855 | i::Object* length = obj->length(); |
| 5856 | if (length->IsSmi()) { |
| 5857 | return i::Smi::cast(length)->value(); |
| 5858 | } else { |
| 5859 | return static_cast<uint32_t>(length->Number()); |
| 5860 | } |
| 5861 | } |
| 5862 | |
| 5863 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5864 | Local<Object> Array::CloneElementAt(uint32_t index) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5865 | i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5866 | ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5867 | i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5868 | if (!self->HasFastObjectElements()) { |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5869 | return Local<Object>(); |
| 5870 | } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 5871 | i::FixedArray* elms = i::FixedArray::cast(self->elements()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5872 | i::Object* paragon = elms->get(index); |
| 5873 | if (!paragon->IsJSObject()) { |
| 5874 | return Local<Object>(); |
| 5875 | } |
| 5876 | i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5877 | EXCEPTION_PREAMBLE(isolate); |
| 5878 | ENTER_V8(isolate); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5879 | i::Handle<i::JSObject> result = i::JSObject::Copy(paragon_handle); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5880 | has_pending_exception = result.is_null(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5881 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 5882 | return Utils::ToLocal(result); |
| 5883 | } |
| 5884 | |
| 5885 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5886 | bool v8::ArrayBuffer::IsExternal() const { |
| 5887 | return Utils::OpenHandle(this)->is_external(); |
| 5888 | } |
| 5889 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 5890 | |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 5891 | v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5892 | i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); |
| 5893 | ApiCheck(!obj->is_external(), |
| 5894 | "v8::ArrayBuffer::Externalize", |
| 5895 | "ArrayBuffer already externalized"); |
| 5896 | obj->set_is_external(true); |
| 5897 | 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] | 5898 | Contents contents; |
| 5899 | contents.data_ = obj->backing_store(); |
| 5900 | contents.byte_length_ = byte_length; |
| 5901 | return contents; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 5905 | void v8::ArrayBuffer::Neuter() { |
| 5906 | i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); |
| 5907 | i::Isolate* isolate = obj->GetIsolate(); |
| 5908 | ApiCheck(obj->is_external(), |
| 5909 | "v8::ArrayBuffer::Neuter", |
| 5910 | "Only externalized ArrayBuffers can be neutered"); |
| 5911 | LOG_API(obj->GetIsolate(), "v8::ArrayBuffer::Neuter()"); |
| 5912 | ENTER_V8(isolate); |
| 5913 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5914 | for (i::Handle<i::Object> view_obj(obj->weak_first_view(), isolate); |
| 5915 | !view_obj->IsUndefined();) { |
| 5916 | i::Handle<i::JSArrayBufferView> view(i::JSArrayBufferView::cast(*view_obj)); |
| 5917 | if (view->IsJSTypedArray()) { |
| 5918 | i::JSTypedArray::cast(*view)->Neuter(); |
| 5919 | } else if (view->IsJSDataView()) { |
| 5920 | i::JSDataView::cast(*view)->Neuter(); |
| 5921 | } else { |
| 5922 | UNREACHABLE(); |
| 5923 | } |
| 5924 | view_obj = i::handle(view->weak_next(), isolate); |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 5925 | } |
| 5926 | obj->Neuter(); |
| 5927 | } |
| 5928 | |
| 5929 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5930 | size_t v8::ArrayBuffer::ByteLength() const { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5931 | i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this); |
| 5932 | return static_cast<size_t>(obj->byte_length()->Number()); |
| 5933 | } |
| 5934 | |
| 5935 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5936 | Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) { |
| 5937 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5938 | EnsureInitializedForIsolate(i_isolate, "v8::ArrayBuffer::New(size_t)"); |
| 5939 | LOG_API(i_isolate, "v8::ArrayBuffer::New(size_t)"); |
| 5940 | ENTER_V8(i_isolate); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5941 | i::Handle<i::JSArrayBuffer> obj = |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5942 | i_isolate->factory()->NewJSArrayBuffer(); |
| 5943 | i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length); |
| 5944 | return Utils::ToLocal(obj); |
| 5945 | } |
| 5946 | |
| 5947 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 5948 | Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data, |
| 5949 | size_t byte_length) { |
| 5950 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5951 | EnsureInitializedForIsolate(i_isolate, "v8::ArrayBuffer::New(void*, size_t)"); |
| 5952 | LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)"); |
| 5953 | ENTER_V8(i_isolate); |
| 5954 | i::Handle<i::JSArrayBuffer> obj = |
| 5955 | i_isolate->factory()->NewJSArrayBuffer(); |
| 5956 | i::Runtime::SetupArrayBuffer(i_isolate, obj, true, data, byte_length); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5957 | return Utils::ToLocal(obj); |
| 5958 | } |
| 5959 | |
| 5960 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5961 | Local<ArrayBuffer> v8::ArrayBufferView::Buffer() { |
| 5962 | i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5963 | ASSERT(obj->buffer()->IsJSArrayBuffer()); |
| 5964 | i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer())); |
| 5965 | return Utils::ToLocal(buffer); |
| 5966 | } |
| 5967 | |
| 5968 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5969 | size_t v8::ArrayBufferView::ByteOffset() { |
| 5970 | i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5971 | return static_cast<size_t>(obj->byte_offset()->Number()); |
| 5972 | } |
| 5973 | |
| 5974 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5975 | size_t v8::ArrayBufferView::ByteLength() { |
| 5976 | i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5977 | return static_cast<size_t>(obj->byte_length()->Number()); |
| 5978 | } |
| 5979 | |
| 5980 | |
| 5981 | size_t v8::TypedArray::Length() { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5982 | i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this); |
| 5983 | return static_cast<size_t>(obj->length()->Number()); |
| 5984 | } |
| 5985 | |
| 5986 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5987 | static inline void SetupArrayBufferView( |
| 5988 | i::Isolate* isolate, |
| 5989 | i::Handle<i::JSArrayBufferView> obj, |
| 5990 | i::Handle<i::JSArrayBuffer> buffer, |
| 5991 | size_t byte_offset, |
| 5992 | size_t byte_length) { |
| 5993 | ASSERT(byte_offset + byte_length <= |
| 5994 | static_cast<size_t>(buffer->byte_length()->Number())); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 5995 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5996 | obj->set_buffer(*buffer); |
| 5997 | |
| 5998 | obj->set_weak_next(buffer->weak_first_view()); |
| 5999 | buffer->set_weak_first_view(*obj); |
| 6000 | |
| 6001 | i::Handle<i::Object> byte_offset_object = |
| 6002 | isolate->factory()->NewNumberFromSize(byte_offset); |
| 6003 | obj->set_byte_offset(*byte_offset_object); |
| 6004 | |
| 6005 | i::Handle<i::Object> byte_length_object = |
| 6006 | isolate->factory()->NewNumberFromSize(byte_length); |
| 6007 | obj->set_byte_length(*byte_length_object); |
| 6008 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6009 | |
| 6010 | template<typename ElementType, |
| 6011 | ExternalArrayType array_type, |
| 6012 | i::ElementsKind elements_kind> |
| 6013 | i::Handle<i::JSTypedArray> NewTypedArray( |
| 6014 | i::Isolate* isolate, |
| 6015 | Handle<ArrayBuffer> array_buffer, size_t byte_offset, size_t length) { |
| 6016 | i::Handle<i::JSTypedArray> obj = |
| 6017 | isolate->factory()->NewJSTypedArray(array_type); |
| 6018 | i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); |
| 6019 | |
| 6020 | ASSERT(byte_offset % sizeof(ElementType) == 0); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6021 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 6022 | CHECK(length <= (std::numeric_limits<size_t>::max() / sizeof(ElementType))); |
| 6023 | size_t byte_length = length * sizeof(ElementType); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6024 | SetupArrayBufferView( |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 6025 | isolate, obj, buffer, byte_offset, byte_length); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6026 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6027 | i::Handle<i::Object> length_object = |
| 6028 | isolate->factory()->NewNumberFromSize(length); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6029 | obj->set_length(*length_object); |
| 6030 | |
| 6031 | i::Handle<i::ExternalArray> elements = |
| 6032 | isolate->factory()->NewExternalArray( |
| 6033 | static_cast<int>(length), array_type, |
| 6034 | static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6035 | obj->set_elements(*elements); |
| 6036 | return obj; |
| 6037 | } |
| 6038 | |
| 6039 | |
| 6040 | #define TYPED_ARRAY_NEW(TypedArray, element_type, array_type, elements_kind) \ |
| 6041 | Local<TypedArray> TypedArray::New(Handle<ArrayBuffer> array_buffer, \ |
| 6042 | size_t byte_offset, size_t length) { \ |
| 6043 | i::Isolate* isolate = i::Isolate::Current(); \ |
| 6044 | EnsureInitializedForIsolate(isolate, \ |
| 6045 | "v8::" #TypedArray "::New(Handle<ArrayBuffer>, size_t, size_t)"); \ |
| 6046 | LOG_API(isolate, \ |
| 6047 | "v8::" #TypedArray "::New(Handle<ArrayBuffer>, size_t, size_t)"); \ |
| 6048 | ENTER_V8(isolate); \ |
| 6049 | i::Handle<i::JSTypedArray> obj = \ |
| 6050 | NewTypedArray<element_type, array_type, elements_kind>( \ |
| 6051 | isolate, array_buffer, byte_offset, length); \ |
| 6052 | return Utils::ToLocal##TypedArray(obj); \ |
| 6053 | } |
| 6054 | |
| 6055 | |
| 6056 | TYPED_ARRAY_NEW(Uint8Array, uint8_t, kExternalUnsignedByteArray, |
| 6057 | i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS) |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6058 | TYPED_ARRAY_NEW(Uint8ClampedArray, uint8_t, kExternalPixelArray, |
| 6059 | i::EXTERNAL_PIXEL_ELEMENTS) |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6060 | TYPED_ARRAY_NEW(Int8Array, int8_t, kExternalByteArray, |
| 6061 | i::EXTERNAL_BYTE_ELEMENTS) |
| 6062 | TYPED_ARRAY_NEW(Uint16Array, uint16_t, kExternalUnsignedShortArray, |
| 6063 | i::EXTERNAL_UNSIGNED_SHORT_ELEMENTS) |
| 6064 | TYPED_ARRAY_NEW(Int16Array, int16_t, kExternalShortArray, |
| 6065 | i::EXTERNAL_SHORT_ELEMENTS) |
| 6066 | TYPED_ARRAY_NEW(Uint32Array, uint32_t, kExternalUnsignedIntArray, |
| 6067 | i::EXTERNAL_UNSIGNED_INT_ELEMENTS) |
| 6068 | TYPED_ARRAY_NEW(Int32Array, int32_t, kExternalIntArray, |
| 6069 | i::EXTERNAL_INT_ELEMENTS) |
| 6070 | TYPED_ARRAY_NEW(Float32Array, float, kExternalFloatArray, |
| 6071 | i::EXTERNAL_FLOAT_ELEMENTS) |
| 6072 | TYPED_ARRAY_NEW(Float64Array, double, kExternalDoubleArray, |
| 6073 | i::EXTERNAL_DOUBLE_ELEMENTS) |
| 6074 | |
| 6075 | #undef TYPED_ARRAY_NEW |
| 6076 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6077 | Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer, |
| 6078 | size_t byte_offset, size_t byte_length) { |
| 6079 | i::Isolate* isolate = i::Isolate::Current(); |
| 6080 | EnsureInitializedForIsolate( |
| 6081 | isolate, "v8::DataView::New(void*, size_t, size_t)"); |
| 6082 | LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)"); |
| 6083 | ENTER_V8(isolate); |
| 6084 | i::Handle<i::JSDataView> obj = isolate->factory()->NewJSDataView(); |
| 6085 | i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); |
| 6086 | SetupArrayBufferView( |
| 6087 | isolate, obj, buffer, byte_offset, byte_length); |
| 6088 | return Utils::ToLocal(obj); |
| 6089 | } |
| 6090 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 6091 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 6092 | Local<Symbol> v8::Symbol::New(Isolate* isolate, const char* data, int length) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6093 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6094 | EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()"); |
| 6095 | LOG_API(i_isolate, "Symbol::New()"); |
| 6096 | ENTER_V8(i_isolate); |
| 6097 | i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 6098 | if (data != NULL) { |
| 6099 | if (length == -1) length = i::StrLength(data); |
| 6100 | i::Handle<i::String> name = i_isolate->factory()->NewStringFromUtf8( |
| 6101 | i::Vector<const char>(data, length)); |
| 6102 | result->set_name(*name); |
| 6103 | } |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6104 | return Utils::ToLocal(result); |
| 6105 | } |
| 6106 | |
| 6107 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 6108 | Local<Private> v8::Private::New( |
| 6109 | Isolate* isolate, const char* data, int length) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6110 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 6111 | EnsureInitializedForIsolate(i_isolate, "v8::Private::New()"); |
| 6112 | LOG_API(i_isolate, "Private::New()"); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6113 | ENTER_V8(i_isolate); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 6114 | i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); |
| 6115 | if (data != NULL) { |
| 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 | symbol->set_name(*name); |
| 6120 | } |
| 6121 | Local<Symbol> result = Utils::ToLocal(symbol); |
| 6122 | return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 6123 | } |
| 6124 | |
| 6125 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6126 | Local<Number> v8::Number::New(Isolate* isolate, double value) { |
| 6127 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6128 | ASSERT(internal_isolate->IsInitialized()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 6129 | if (std::isnan(value)) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6130 | // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 6131 | value = i::OS::nan_value(); |
| 6132 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 6133 | ENTER_V8(internal_isolate); |
| 6134 | i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6135 | return Utils::NumberToLocal(result); |
| 6136 | } |
| 6137 | |
| 6138 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 6139 | Local<Integer> v8::Integer::New(Isolate* isolate, int32_t value) { |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 6140 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6141 | ASSERT(internal_isolate->IsInitialized()); |
| 6142 | if (i::Smi::IsValid(value)) { |
| 6143 | return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value), |
| 6144 | internal_isolate)); |
| 6145 | } |
| 6146 | ENTER_V8(internal_isolate); |
| 6147 | i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); |
| 6148 | return Utils::IntegerToLocal(result); |
| 6149 | } |
| 6150 | |
| 6151 | |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 6152 | Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) { |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 6153 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6154 | ASSERT(internal_isolate->IsInitialized()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6155 | bool fits_into_int32_t = (value & (1 << 31)) == 0; |
| 6156 | if (fits_into_int32_t) { |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 6157 | return Integer::New(isolate, static_cast<int32_t>(value)); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6158 | } |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 6159 | ENTER_V8(internal_isolate); |
| 6160 | i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6161 | return Utils::IntegerToLocal(result); |
| 6162 | } |
| 6163 | |
| 6164 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6165 | #ifdef DEBUG |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 6166 | v8::AssertNoGCScope::AssertNoGCScope(v8::Isolate* isolate) { |
| 6167 | disallow_heap_allocation_ = new i::DisallowHeapAllocation(); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6168 | } |
| 6169 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6170 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6171 | v8::AssertNoGCScope::~AssertNoGCScope() { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 6172 | delete static_cast<i::DisallowHeapAllocation*>(disallow_heap_allocation_); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6173 | } |
| 6174 | #endif |
| 6175 | |
| 6176 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6177 | void V8::IgnoreOutOfMemoryException() { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 6178 | EnterIsolateIfNeeded()->set_ignore_out_of_memory(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6182 | bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6183 | i::Isolate* isolate = i::Isolate::Current(); |
| 6184 | EnsureInitializedForIsolate(isolate, "v8::V8::AddMessageListener()"); |
| 6185 | ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6186 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6187 | i::HandleScope scope(isolate); |
| 6188 | NeanderArray listeners(isolate->factory()->message_listeners()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6189 | NeanderObject obj(2); |
| 6190 | obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that))); |
| 6191 | obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value() |
| 6192 | : *Utils::OpenHandle(*data)); |
| 6193 | listeners.add(obj.value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6194 | return true; |
| 6195 | } |
| 6196 | |
| 6197 | |
| 6198 | void V8::RemoveMessageListeners(MessageCallback that) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6199 | i::Isolate* isolate = i::Isolate::Current(); |
| 6200 | EnsureInitializedForIsolate(isolate, "v8::V8::RemoveMessageListener()"); |
| 6201 | ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6202 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6203 | i::HandleScope scope(isolate); |
| 6204 | NeanderArray listeners(isolate->factory()->message_listeners()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6205 | for (int i = 0; i < listeners.length(); i++) { |
| 6206 | if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones |
| 6207 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6208 | NeanderObject listener(i::JSObject::cast(listeners.get(i))); |
| 6209 | 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] | 6210 | if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6211 | listeners.set(i, isolate->heap()->undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6212 | } |
| 6213 | } |
| 6214 | } |
| 6215 | |
| 6216 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 6217 | void V8::SetCaptureStackTraceForUncaughtExceptions( |
| 6218 | bool capture, |
| 6219 | int frame_limit, |
| 6220 | StackTrace::StackTraceOptions options) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6221 | i::Isolate::Current()->SetCaptureStackTraceForUncaughtExceptions( |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 6222 | capture, |
| 6223 | frame_limit, |
| 6224 | options); |
| 6225 | } |
| 6226 | |
| 6227 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6228 | void V8::SetCounterFunction(CounterLookupCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 6229 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6230 | isolate->stats_table()->SetCounterFunction(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6231 | } |
| 6232 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6233 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6234 | void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 6235 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6236 | isolate->stats_table()->SetCreateHistogramFunction(callback); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 6237 | isolate->InitializeLoggingAndCounters(); |
| 6238 | isolate->counters()->ResetHistograms(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6239 | } |
| 6240 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6241 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6242 | void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback callback) { |
sgjesse@chromium.org | e059905 | 2011-03-25 07:34:35 +0000 | [diff] [blame] | 6243 | i::Isolate* isolate = EnterIsolateIfNeeded(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6244 | isolate->stats_table()-> |
| 6245 | SetAddHistogramSampleFunction(callback); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6246 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6247 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6248 | void V8::SetFailedAccessCheckCallbackFunction( |
| 6249 | FailedAccessCheckCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6250 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6251 | isolate->SetFailedAccessCheckCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6252 | } |
| 6253 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 6254 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 6255 | int64_t Isolate::AdjustAmountOfExternalAllocatedMemory( |
| 6256 | int64_t change_in_bytes) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 6257 | i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap(); |
| 6258 | return heap->AdjustAmountOfExternalAllocatedMemory(change_in_bytes); |
| 6259 | } |
| 6260 | |
| 6261 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6262 | HeapProfiler* Isolate::GetHeapProfiler() { |
| 6263 | i::HeapProfiler* heap_profiler = |
| 6264 | reinterpret_cast<i::Isolate*>(this)->heap_profiler(); |
| 6265 | return reinterpret_cast<HeapProfiler*>(heap_profiler); |
| 6266 | } |
| 6267 | |
| 6268 | |
| 6269 | CpuProfiler* Isolate::GetCpuProfiler() { |
| 6270 | i::CpuProfiler* cpu_profiler = |
| 6271 | reinterpret_cast<i::Isolate*>(this)->cpu_profiler(); |
| 6272 | return reinterpret_cast<CpuProfiler*>(cpu_profiler); |
| 6273 | } |
| 6274 | |
| 6275 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6276 | bool Isolate::InContext() { |
| 6277 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6278 | return isolate->context() != NULL; |
| 6279 | } |
| 6280 | |
| 6281 | |
mvstanton@chromium.org | 40ce96b | 2013-04-09 09:52:22 +0000 | [diff] [blame] | 6282 | v8::Local<v8::Context> Isolate::GetCurrentContext() { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6283 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6284 | i::Context* context = isolate->context(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6285 | if (context == NULL) return Local<Context>(); |
| 6286 | i::Context* native_context = context->global_object()->native_context(); |
| 6287 | if (native_context == NULL) return Local<Context>(); |
| 6288 | return Utils::ToLocal(i::Handle<i::Context>(native_context)); |
mvstanton@chromium.org | 40ce96b | 2013-04-09 09:52:22 +0000 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6292 | v8::Local<v8::Context> Isolate::GetCallingContext() { |
| 6293 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6294 | i::Handle<i::Object> calling = isolate->GetCallingNativeContext(); |
| 6295 | if (calling.is_null()) return Local<Context>(); |
| 6296 | return Utils::ToLocal(i::Handle<i::Context>::cast(calling)); |
| 6297 | } |
| 6298 | |
| 6299 | |
| 6300 | v8::Local<v8::Context> Isolate::GetEnteredContext() { |
| 6301 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6302 | i::Handle<i::Object> last = |
| 6303 | isolate->handle_scope_implementer()->LastEnteredContext(); |
| 6304 | if (last.is_null()) return Local<Context>(); |
| 6305 | return Utils::ToLocal(i::Handle<i::Context>::cast(last)); |
| 6306 | } |
| 6307 | |
| 6308 | |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 6309 | v8::Local<Value> Isolate::ThrowException(v8::Local<v8::Value> value) { |
| 6310 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6311 | ENTER_V8(isolate); |
| 6312 | // If we're passed an empty handle, we throw an undefined exception |
| 6313 | // to deal more gracefully with out of memory situations. |
| 6314 | if (value.IsEmpty()) { |
| 6315 | isolate->ScheduleThrow(isolate->heap()->undefined_value()); |
| 6316 | } else { |
| 6317 | isolate->ScheduleThrow(*Utils::OpenHandle(*value)); |
| 6318 | } |
| 6319 | return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 6320 | } |
| 6321 | |
| 6322 | |
mstarzinger@chromium.org | 6900838 | 2013-10-18 10:34:25 +0000 | [diff] [blame] | 6323 | void Isolate::SetObjectGroupId(internal::Object** object, UniqueId id) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6324 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); |
| 6325 | internal_isolate->global_handles()->SetObjectGroupId( |
mstarzinger@chromium.org | 6900838 | 2013-10-18 10:34:25 +0000 | [diff] [blame] | 6326 | v8::internal::Handle<v8::internal::Object>(object).location(), |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6327 | id); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6328 | } |
| 6329 | |
| 6330 | |
mstarzinger@chromium.org | 6900838 | 2013-10-18 10:34:25 +0000 | [diff] [blame] | 6331 | void Isolate::SetReferenceFromGroup(UniqueId id, internal::Object** object) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6332 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6333 | internal_isolate->global_handles()->SetReferenceFromGroup( |
| 6334 | id, |
mstarzinger@chromium.org | 6900838 | 2013-10-18 10:34:25 +0000 | [diff] [blame] | 6335 | v8::internal::Handle<v8::internal::Object>(object).location()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | |
mstarzinger@chromium.org | 6900838 | 2013-10-18 10:34:25 +0000 | [diff] [blame] | 6339 | void Isolate::SetReference(internal::Object** parent, |
| 6340 | internal::Object** child) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6341 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this); |
mstarzinger@chromium.org | 6900838 | 2013-10-18 10:34:25 +0000 | [diff] [blame] | 6342 | i::Object** parent_location = |
| 6343 | v8::internal::Handle<v8::internal::Object>(parent).location(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6344 | internal_isolate->global_handles()->SetReference( |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6345 | reinterpret_cast<i::HeapObject**>(parent_location), |
mstarzinger@chromium.org | 6900838 | 2013-10-18 10:34:25 +0000 | [diff] [blame] | 6346 | v8::internal::Handle<v8::internal::Object>(child).location()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 6347 | } |
| 6348 | |
| 6349 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6350 | void Isolate::AddGCPrologueCallback(GCPrologueCallback callback, |
| 6351 | GCType gc_type) { |
| 6352 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6353 | isolate->heap()->AddGCPrologueCallback(callback, gc_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6354 | } |
| 6355 | |
| 6356 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6357 | void Isolate::RemoveGCPrologueCallback(GCPrologueCallback callback) { |
| 6358 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6359 | isolate->heap()->RemoveGCPrologueCallback(callback); |
| 6360 | } |
| 6361 | |
| 6362 | |
| 6363 | void Isolate::AddGCEpilogueCallback(GCEpilogueCallback callback, |
| 6364 | GCType gc_type) { |
| 6365 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6366 | isolate->heap()->AddGCEpilogueCallback(callback, gc_type); |
| 6367 | } |
| 6368 | |
| 6369 | |
| 6370 | void Isolate::RemoveGCEpilogueCallback(GCEpilogueCallback callback) { |
| 6371 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6372 | isolate->heap()->RemoveGCEpilogueCallback(callback); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6376 | void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6377 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6378 | isolate->heap()->AddGCPrologueCallback( |
| 6379 | reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback), |
| 6380 | gc_type, |
| 6381 | false); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6382 | } |
| 6383 | |
| 6384 | |
| 6385 | void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6386 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6387 | isolate->heap()->RemoveGCPrologueCallback( |
| 6388 | reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6389 | } |
| 6390 | |
| 6391 | |
| 6392 | void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6393 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6394 | isolate->heap()->AddGCEpilogueCallback( |
| 6395 | reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback), |
| 6396 | gc_type, |
| 6397 | false); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | |
| 6401 | void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6402 | i::Isolate* isolate = i::Isolate::Current(); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6403 | isolate->heap()->RemoveGCEpilogueCallback( |
| 6404 | reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 6405 | } |
| 6406 | |
| 6407 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6408 | void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 6409 | ObjectSpace space, |
| 6410 | AllocationAction action) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6411 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6412 | isolate->memory_allocator()->AddMemoryAllocationCallback( |
| 6413 | callback, space, action); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6414 | } |
| 6415 | |
| 6416 | |
| 6417 | void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6418 | i::Isolate* isolate = i::Isolate::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6419 | isolate->memory_allocator()->RemoveMemoryAllocationCallback( |
| 6420 | callback); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6421 | } |
| 6422 | |
| 6423 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6424 | void V8::AddCallCompletedCallback(CallCompletedCallback callback) { |
| 6425 | if (callback == NULL) return; |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6426 | i::V8::AddCallCompletedCallback(callback); |
| 6427 | } |
| 6428 | |
| 6429 | |
| 6430 | void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6431 | i::V8::RemoveCallCompletedCallback(callback); |
| 6432 | } |
| 6433 | |
| 6434 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6435 | void V8::TerminateExecution(Isolate* isolate) { |
| 6436 | // If no isolate is supplied, use the default isolate. |
| 6437 | if (isolate != NULL) { |
| 6438 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution(); |
| 6439 | } else { |
| 6440 | i::Isolate::GetDefaultIsolateStackGuard()->TerminateExecution(); |
| 6441 | } |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 6442 | } |
| 6443 | |
| 6444 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 6445 | bool V8::IsExecutionTerminating(Isolate* isolate) { |
| 6446 | i::Isolate* i_isolate = isolate != NULL ? |
| 6447 | reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current(); |
| 6448 | return IsExecutionTerminatingCheck(i_isolate); |
sgjesse@chromium.org | 2ab9952 | 2010-03-10 09:03:43 +0000 | [diff] [blame] | 6449 | } |
| 6450 | |
| 6451 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 6452 | void V8::CancelTerminateExecution(Isolate* isolate) { |
| 6453 | i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6454 | i_isolate->stack_guard()->CancelTerminateExecution(); |
| 6455 | } |
| 6456 | |
| 6457 | |
hpayer@chromium.org | ea9b8ba | 2013-12-20 19:22:39 +0000 | [diff] [blame] | 6458 | void Isolate::RequestInterrupt(InterruptCallback callback, void* data) { |
| 6459 | reinterpret_cast<i::Isolate*>(this)->stack_guard()->RequestInterrupt( |
| 6460 | callback, data); |
| 6461 | } |
| 6462 | |
| 6463 | |
| 6464 | void Isolate::ClearInterrupt() { |
| 6465 | reinterpret_cast<i::Isolate*>(this)->stack_guard()->ClearInterrupt(); |
| 6466 | } |
| 6467 | |
| 6468 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6469 | Isolate* Isolate::GetCurrent() { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 6470 | i::Isolate* isolate = i::Isolate::UncheckedCurrent(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6471 | return reinterpret_cast<Isolate*>(isolate); |
| 6472 | } |
| 6473 | |
| 6474 | |
| 6475 | Isolate* Isolate::New() { |
| 6476 | i::Isolate* isolate = new i::Isolate(); |
| 6477 | return reinterpret_cast<Isolate*>(isolate); |
| 6478 | } |
| 6479 | |
| 6480 | |
| 6481 | void Isolate::Dispose() { |
| 6482 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6483 | if (!ApiCheck(!isolate->IsInUse(), |
| 6484 | "v8::Isolate::Dispose()", |
| 6485 | "Disposing the isolate that is entered by a thread.")) { |
| 6486 | return; |
| 6487 | } |
| 6488 | isolate->TearDown(); |
| 6489 | } |
| 6490 | |
| 6491 | |
| 6492 | void Isolate::Enter() { |
| 6493 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6494 | isolate->Enter(); |
| 6495 | } |
| 6496 | |
| 6497 | |
| 6498 | void Isolate::Exit() { |
| 6499 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| 6500 | isolate->Exit(); |
| 6501 | } |
| 6502 | |
| 6503 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6504 | void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) { |
| 6505 | i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6506 | if (!isolate->IsInitialized()) { |
| 6507 | heap_statistics->total_heap_size_ = 0; |
| 6508 | heap_statistics->total_heap_size_executable_ = 0; |
| 6509 | heap_statistics->total_physical_size_ = 0; |
| 6510 | heap_statistics->used_heap_size_ = 0; |
| 6511 | heap_statistics->heap_size_limit_ = 0; |
| 6512 | return; |
| 6513 | } |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 6514 | i::Heap* heap = isolate->heap(); |
| 6515 | heap_statistics->total_heap_size_ = heap->CommittedMemory(); |
| 6516 | heap_statistics->total_heap_size_executable_ = |
| 6517 | heap->CommittedMemoryExecutable(); |
| 6518 | heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory(); |
| 6519 | heap_statistics->used_heap_size_ = heap->SizeOfObjects(); |
| 6520 | heap_statistics->heap_size_limit_ = heap->MaxReserved(); |
| 6521 | } |
| 6522 | |
| 6523 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6524 | String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) |
| 6525 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6526 | i::Isolate* isolate = i::Isolate::Current(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6527 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6528 | ENTER_V8(isolate); |
| 6529 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6530 | TryCatch try_catch; |
| 6531 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6532 | if (str.IsEmpty()) return; |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 6533 | i::Handle<i::String> i_str = Utils::OpenHandle(*str); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 6534 | length_ = v8::Utf8Length(*i_str, isolate); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6535 | str_ = i::NewArray<char>(length_ + 1); |
| 6536 | str->WriteUtf8(str_); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6537 | } |
| 6538 | |
| 6539 | |
| 6540 | String::Utf8Value::~Utf8Value() { |
| 6541 | i::DeleteArray(str_); |
| 6542 | } |
| 6543 | |
| 6544 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6545 | String::Value::Value(v8::Handle<v8::Value> obj) |
| 6546 | : str_(NULL), length_(0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6547 | i::Isolate* isolate = i::Isolate::Current(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6548 | if (obj.IsEmpty()) return; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6549 | ENTER_V8(isolate); |
| 6550 | i::HandleScope scope(isolate); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6551 | TryCatch try_catch; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6552 | Handle<String> str = obj->ToString(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6553 | if (str.IsEmpty()) return; |
| 6554 | length_ = str->Length(); |
| 6555 | str_ = i::NewArray<uint16_t>(length_ + 1); |
| 6556 | str->Write(str_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6557 | } |
| 6558 | |
| 6559 | |
| 6560 | String::Value::~Value() { |
| 6561 | i::DeleteArray(str_); |
| 6562 | } |
| 6563 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6564 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6565 | Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6566 | i::Isolate* isolate = i::Isolate::Current(); |
| 6567 | LOG_API(isolate, "RangeError"); |
| 6568 | ON_BAILOUT(isolate, "v8::Exception::RangeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6569 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6570 | i::Object* error; |
| 6571 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6572 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6573 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6574 | i::Handle<i::Object> result = isolate->factory()->NewRangeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6575 | error = *result; |
| 6576 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6577 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6578 | return Utils::ToLocal(result); |
| 6579 | } |
| 6580 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6581 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6582 | Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6583 | i::Isolate* isolate = i::Isolate::Current(); |
| 6584 | LOG_API(isolate, "ReferenceError"); |
| 6585 | ON_BAILOUT(isolate, "v8::Exception::ReferenceError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6586 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6587 | i::Object* error; |
| 6588 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6589 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6590 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6591 | i::Handle<i::Object> result = |
| 6592 | isolate->factory()->NewReferenceError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6593 | error = *result; |
| 6594 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6595 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6596 | return Utils::ToLocal(result); |
| 6597 | } |
| 6598 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6599 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6600 | Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6601 | i::Isolate* isolate = i::Isolate::Current(); |
| 6602 | LOG_API(isolate, "SyntaxError"); |
| 6603 | ON_BAILOUT(isolate, "v8::Exception::SyntaxError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6604 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6605 | i::Object* error; |
| 6606 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6607 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6608 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6609 | i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6610 | error = *result; |
| 6611 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6612 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6613 | return Utils::ToLocal(result); |
| 6614 | } |
| 6615 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6616 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6617 | Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6618 | i::Isolate* isolate = i::Isolate::Current(); |
| 6619 | LOG_API(isolate, "TypeError"); |
| 6620 | ON_BAILOUT(isolate, "v8::Exception::TypeError()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6621 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6622 | i::Object* error; |
| 6623 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6624 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6625 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6626 | i::Handle<i::Object> result = isolate->factory()->NewTypeError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6627 | error = *result; |
| 6628 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6629 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6630 | return Utils::ToLocal(result); |
| 6631 | } |
| 6632 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 6633 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6634 | Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6635 | i::Isolate* isolate = i::Isolate::Current(); |
| 6636 | LOG_API(isolate, "Error"); |
| 6637 | ON_BAILOUT(isolate, "v8::Exception::Error()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6638 | ENTER_V8(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6639 | i::Object* error; |
| 6640 | { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6641 | i::HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6642 | i::Handle<i::String> message = Utils::OpenHandle(*raw_message); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6643 | i::Handle<i::Object> result = isolate->factory()->NewError(message); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6644 | error = *result; |
| 6645 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6646 | i::Handle<i::Object> result(error, isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6647 | return Utils::ToLocal(result); |
| 6648 | } |
| 6649 | |
| 6650 | |
| 6651 | // --- D e b u g S u p p o r t --- |
| 6652 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6653 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6654 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6655 | bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6656 | i::Isolate* isolate = i::Isolate::Current(); |
| 6657 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()"); |
| 6658 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener2()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6659 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6660 | i::HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6661 | i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 6662 | if (that != NULL) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6663 | foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that)); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 6664 | } |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 6665 | isolate->debugger()->SetEventListener(foreign, |
| 6666 | Utils::OpenHandle(*data, true)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6667 | return true; |
| 6668 | } |
| 6669 | |
| 6670 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 6671 | bool Debug::SetDebugEventListener(v8::Handle<v8::Object> that, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6672 | Handle<Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6673 | i::Isolate* isolate = i::Isolate::Current(); |
| 6674 | ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6675 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6676 | isolate->debugger()->SetEventListener(Utils::OpenHandle(*that), |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 6677 | Utils::OpenHandle(*data, true)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6678 | return true; |
| 6679 | } |
| 6680 | |
| 6681 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6682 | void Debug::DebugBreak(Isolate* isolate) { |
| 6683 | // If no isolate is supplied, use the default isolate. |
| 6684 | if (isolate != NULL) { |
| 6685 | reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->DebugBreak(); |
| 6686 | } else { |
| 6687 | i::Isolate::GetDefaultIsolateStackGuard()->DebugBreak(); |
| 6688 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6689 | } |
| 6690 | |
| 6691 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6692 | void Debug::CancelDebugBreak(Isolate* isolate) { |
| 6693 | // If no isolate is supplied, use the default isolate. |
| 6694 | if (isolate != NULL) { |
| 6695 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6696 | internal_isolate->stack_guard()->Continue(i::DEBUGBREAK); |
| 6697 | } else { |
| 6698 | i::Isolate::GetDefaultIsolateStackGuard()->Continue(i::DEBUGBREAK); |
| 6699 | } |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 6700 | } |
| 6701 | |
| 6702 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6703 | void Debug::DebugBreakForCommand(ClientData* data, Isolate* isolate) { |
| 6704 | // If no isolate is supplied, use the default isolate. |
| 6705 | if (isolate != NULL) { |
| 6706 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6707 | internal_isolate->debugger()->EnqueueDebugCommand(data); |
| 6708 | } else { |
| 6709 | i::Isolate::GetDefaultIsolateDebugger()->EnqueueDebugCommand(data); |
| 6710 | } |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 6711 | } |
| 6712 | |
| 6713 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 6714 | void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6715 | i::Isolate* isolate = i::Isolate::Current(); |
| 6716 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); |
| 6717 | ENTER_V8(isolate); |
| 6718 | isolate->debugger()->SetMessageHandler(handler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6722 | void Debug::SendCommand(Isolate* isolate, |
| 6723 | const uint16_t* command, |
| 6724 | int length, |
| 6725 | ClientData* client_data) { |
| 6726 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6727 | internal_isolate->debugger()->ProcessCommand( |
| 6728 | i::Vector<const uint16_t>(command, length), client_data); |
| 6729 | } |
| 6730 | |
| 6731 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6732 | void Debug::SendCommand(const uint16_t* command, int length, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6733 | ClientData* client_data, |
| 6734 | Isolate* isolate) { |
| 6735 | // If no isolate is supplied, use the default isolate. |
| 6736 | if (isolate != NULL) { |
| 6737 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6738 | internal_isolate->debugger()->ProcessCommand( |
| 6739 | i::Vector<const uint16_t>(command, length), client_data); |
| 6740 | } else { |
| 6741 | i::Isolate::GetDefaultIsolateDebugger()->ProcessCommand( |
| 6742 | i::Vector<const uint16_t>(command, length), client_data); |
| 6743 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6744 | } |
| 6745 | |
| 6746 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6747 | void Debug::SetHostDispatchHandler(HostDispatchHandler handler, |
| 6748 | int period) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6749 | i::Isolate* isolate = i::Isolate::Current(); |
| 6750 | EnsureInitializedForIsolate(isolate, "v8::Debug::SetHostDispatchHandler"); |
| 6751 | ENTER_V8(isolate); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 6752 | isolate->debugger()->SetHostDispatchHandler( |
| 6753 | handler, i::TimeDelta::FromMilliseconds(period)); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 6754 | } |
| 6755 | |
| 6756 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6757 | void Debug::SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6758 | DebugMessageDispatchHandler handler, bool provide_locker) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6759 | i::Isolate* isolate = i::Isolate::Current(); |
| 6760 | EnsureInitializedForIsolate(isolate, |
| 6761 | "v8::Debug::SetDebugMessageDispatchHandler"); |
| 6762 | ENTER_V8(isolate); |
| 6763 | isolate->debugger()->SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6764 | handler, provide_locker); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6765 | } |
| 6766 | |
| 6767 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 6768 | Local<Value> Debug::Call(v8::Handle<v8::Function> fun, |
| 6769 | v8::Handle<v8::Value> data) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6770 | i::Isolate* isolate = i::Isolate::Current(); |
| 6771 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 6772 | ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6773 | ENTER_V8(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6774 | i::Handle<i::Object> result; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6775 | EXCEPTION_PREAMBLE(isolate); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6776 | if (data.IsEmpty()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6777 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 6778 | isolate->factory()->undefined_value(), |
| 6779 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6780 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6781 | result = isolate->debugger()->Call(Utils::OpenHandle(*fun), |
| 6782 | Utils::OpenHandle(*data), |
| 6783 | &has_pending_exception); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6784 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6785 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6786 | return Utils::ToLocal(result); |
| 6787 | } |
| 6788 | |
| 6789 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 6790 | Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6791 | i::Isolate* isolate = i::Isolate::Current(); |
| 6792 | if (!isolate->IsInitialized()) return Local<Value>(); |
| 6793 | ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6794 | ENTER_V8(isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 6795 | v8::EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6796 | i::Debug* isolate_debug = isolate->debug(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6797 | isolate_debug->Load(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 6798 | i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global_object()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6799 | i::Handle<i::String> name = isolate->factory()->InternalizeOneByteString( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 6800 | STATIC_ASCII_VECTOR("MakeMirror")); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 6801 | i::Handle<i::Object> fun_obj = i::GetProperty(isolate, debug, name); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 6802 | i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj); |
| 6803 | v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun); |
| 6804 | const int kArgc = 1; |
| 6805 | v8::Handle<v8::Value> argv[kArgc] = { obj }; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6806 | EXCEPTION_PREAMBLE(isolate); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 6807 | v8::Local<v8::Value> result = |
| 6808 | v8_fun->Call(Utils::ToLocal(debug), kArgc, argv); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6809 | EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 6810 | return scope.Escape(result); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 6811 | } |
| 6812 | |
| 6813 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6814 | 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] | 6815 | return i::Isolate::Current()->debugger()->StartAgent(name, port, |
| 6816 | wait_for_connection); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6817 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6818 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6819 | |
| 6820 | void Debug::DisableAgent() { |
| 6821 | return i::Isolate::Current()->debugger()->StopAgent(); |
| 6822 | } |
| 6823 | |
| 6824 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6825 | void Debug::ProcessDebugMessages() { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 6826 | i::Execution::ProcessDebugMessages(i::Isolate::Current(), true); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6827 | } |
| 6828 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 6829 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 6830 | Local<Context> Debug::GetDebugContext() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6831 | i::Isolate* isolate = i::Isolate::Current(); |
| 6832 | EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()"); |
| 6833 | ENTER_V8(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6834 | return Utils::ToLocal(i::Isolate::Current()->debugger()->GetDebugContext()); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 6835 | } |
| 6836 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 6837 | |
| 6838 | void Debug::SetLiveEditEnabled(bool enable, Isolate* isolate) { |
| 6839 | // If no isolate is supplied, use the default isolate. |
| 6840 | i::Debugger* debugger; |
| 6841 | if (isolate != NULL) { |
| 6842 | i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6843 | debugger = internal_isolate->debugger(); |
| 6844 | } else { |
| 6845 | debugger = i::Isolate::GetDefaultIsolateDebugger(); |
| 6846 | } |
| 6847 | debugger->set_live_edit_enabled(enable); |
| 6848 | } |
| 6849 | |
| 6850 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6851 | #endif // ENABLE_DEBUGGER_SUPPORT |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6852 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6853 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6854 | Handle<String> CpuProfileNode::GetFunctionName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6855 | i::Isolate* isolate = i::Isolate::Current(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6856 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
| 6857 | const i::CodeEntry* entry = node->entry(); |
| 6858 | if (!entry->has_name_prefix()) { |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6859 | return ToApiHandle<String>( |
| 6860 | isolate->factory()->InternalizeUtf8String(entry->name())); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6861 | } else { |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6862 | return ToApiHandle<String>(isolate->factory()->NewConsString( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6863 | isolate->factory()->InternalizeUtf8String(entry->name_prefix()), |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6864 | isolate->factory()->InternalizeUtf8String(entry->name()))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6865 | } |
| 6866 | } |
| 6867 | |
| 6868 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 6869 | int CpuProfileNode::GetScriptId() const { |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 6870 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
| 6871 | const i::CodeEntry* entry = node->entry(); |
| 6872 | return entry->script_id(); |
| 6873 | } |
| 6874 | |
| 6875 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6876 | Handle<String> CpuProfileNode::GetScriptResourceName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6877 | i::Isolate* isolate = i::Isolate::Current(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6878 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6879 | return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String( |
| 6880 | node->entry()->resource_name())); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6881 | } |
| 6882 | |
| 6883 | |
| 6884 | int CpuProfileNode::GetLineNumber() const { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6885 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number(); |
| 6886 | } |
| 6887 | |
| 6888 | |
mvstanton@chromium.org | dd6d9ee | 2013-10-11 10:35:37 +0000 | [diff] [blame] | 6889 | int CpuProfileNode::GetColumnNumber() const { |
| 6890 | return reinterpret_cast<const i::ProfileNode*>(this)-> |
| 6891 | entry()->column_number(); |
| 6892 | } |
| 6893 | |
| 6894 | |
jkummerow@chromium.org | 2c9426b | 2013-09-05 16:31:13 +0000 | [diff] [blame] | 6895 | const char* CpuProfileNode::GetBailoutReason() const { |
| 6896 | const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
| 6897 | return node->entry()->bailout_reason(); |
| 6898 | } |
| 6899 | |
| 6900 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 6901 | unsigned CpuProfileNode::GetHitCount() const { |
| 6902 | return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks(); |
| 6903 | } |
| 6904 | |
| 6905 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6906 | unsigned CpuProfileNode::GetCallUid() const { |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 6907 | return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6908 | } |
| 6909 | |
| 6910 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6911 | unsigned CpuProfileNode::GetNodeId() const { |
| 6912 | return reinterpret_cast<const i::ProfileNode*>(this)->id(); |
| 6913 | } |
| 6914 | |
| 6915 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6916 | int CpuProfileNode::GetChildrenCount() const { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6917 | return reinterpret_cast<const i::ProfileNode*>(this)->children()->length(); |
| 6918 | } |
| 6919 | |
| 6920 | |
| 6921 | const CpuProfileNode* CpuProfileNode::GetChild(int index) const { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6922 | const i::ProfileNode* child = |
| 6923 | reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index); |
| 6924 | return reinterpret_cast<const CpuProfileNode*>(child); |
| 6925 | } |
| 6926 | |
| 6927 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6928 | void CpuProfile::Delete() { |
| 6929 | i::Isolate* isolate = i::Isolate::Current(); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6930 | i::CpuProfiler* profiler = isolate->cpu_profiler(); |
| 6931 | ASSERT(profiler != NULL); |
| 6932 | profiler->DeleteProfile(reinterpret_cast<i::CpuProfile*>(this)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6933 | } |
| 6934 | |
| 6935 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6936 | Handle<String> CpuProfile::GetTitle() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6937 | i::Isolate* isolate = i::Isolate::Current(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6938 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 6939 | return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String( |
| 6940 | profile->title())); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6941 | } |
| 6942 | |
| 6943 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6944 | const CpuProfileNode* CpuProfile::GetTopDownRoot() const { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6945 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 6946 | return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root()); |
| 6947 | } |
| 6948 | |
| 6949 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6950 | const CpuProfileNode* CpuProfile::GetSample(int index) const { |
| 6951 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
| 6952 | return reinterpret_cast<const CpuProfileNode*>(profile->sample(index)); |
| 6953 | } |
| 6954 | |
| 6955 | |
danno@chromium.org | 89acc0b | 2013-08-09 20:55:58 +0000 | [diff] [blame] | 6956 | int64_t CpuProfile::GetStartTime() const { |
| 6957 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 6958 | return (profile->start_time() - i::Time::UnixEpoch()).InMicroseconds(); |
danno@chromium.org | 89acc0b | 2013-08-09 20:55:58 +0000 | [diff] [blame] | 6959 | } |
| 6960 | |
| 6961 | |
| 6962 | int64_t CpuProfile::GetEndTime() const { |
| 6963 | const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 6964 | return (profile->end_time() - i::Time::UnixEpoch()).InMicroseconds(); |
danno@chromium.org | 89acc0b | 2013-08-09 20:55:58 +0000 | [diff] [blame] | 6965 | } |
| 6966 | |
| 6967 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6968 | int CpuProfile::GetSamplesCount() const { |
| 6969 | return reinterpret_cast<const i::CpuProfile*>(this)->samples_count(); |
| 6970 | } |
| 6971 | |
| 6972 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 6973 | void CpuProfiler::SetSamplingInterval(int us) { |
| 6974 | ASSERT(us >= 0); |
| 6975 | return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval( |
| 6976 | i::TimeDelta::FromMicroseconds(us)); |
| 6977 | } |
| 6978 | |
| 6979 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 6980 | void CpuProfiler::StartCpuProfiling(Handle<String> title, bool record_samples) { |
| 6981 | reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling( |
| 6982 | *Utils::OpenHandle(*title), record_samples); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 6983 | } |
| 6984 | |
| 6985 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 6986 | const CpuProfile* CpuProfiler::StopCpuProfiling(Handle<String> title) { |
| 6987 | return reinterpret_cast<const CpuProfile*>( |
| 6988 | reinterpret_cast<i::CpuProfiler*>(this)->StopProfiling( |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 6989 | *Utils::OpenHandle(*title))); |
| 6990 | } |
| 6991 | |
| 6992 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 6993 | void CpuProfiler::SetIdle(bool is_idle) { |
| 6994 | i::Isolate* isolate = reinterpret_cast<i::CpuProfiler*>(this)->isolate(); |
| 6995 | i::StateTag state = isolate->current_vm_state(); |
| 6996 | ASSERT(state == i::EXTERNAL || state == i::IDLE); |
| 6997 | if (isolate->js_entry_sp() != NULL) return; |
| 6998 | if (is_idle) { |
| 6999 | isolate->set_current_vm_state(i::IDLE); |
| 7000 | } else if (state == i::IDLE) { |
| 7001 | isolate->set_current_vm_state(i::EXTERNAL); |
| 7002 | } |
| 7003 | } |
| 7004 | |
| 7005 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7006 | static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) { |
| 7007 | return const_cast<i::HeapGraphEdge*>( |
| 7008 | reinterpret_cast<const i::HeapGraphEdge*>(edge)); |
| 7009 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 7010 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7011 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7012 | HeapGraphEdge::Type HeapGraphEdge::GetType() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7013 | return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7014 | } |
| 7015 | |
| 7016 | |
| 7017 | Handle<Value> HeapGraphEdge::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7018 | i::Isolate* isolate = i::Isolate::Current(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7019 | i::HeapGraphEdge* edge = ToInternal(this); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7020 | switch (edge->type()) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7021 | case i::HeapGraphEdge::kContextVariable: |
| 7022 | case i::HeapGraphEdge::kInternal: |
| 7023 | case i::HeapGraphEdge::kProperty: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 7024 | case i::HeapGraphEdge::kShortcut: |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 7025 | return ToApiHandle<String>( |
| 7026 | isolate->factory()->InternalizeUtf8String(edge->name())); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7027 | case i::HeapGraphEdge::kElement: |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 7028 | case i::HeapGraphEdge::kHidden: |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 7029 | case i::HeapGraphEdge::kWeak: |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 7030 | return ToApiHandle<Number>( |
| 7031 | isolate->factory()->NewNumberFromInt(edge->index())); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7032 | default: UNREACHABLE(); |
| 7033 | } |
machenbach@chromium.org | cfdf67d | 2013-09-27 07:27:26 +0000 | [diff] [blame] | 7034 | return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7035 | } |
| 7036 | |
| 7037 | |
| 7038 | const HeapGraphNode* HeapGraphEdge::GetFromNode() const { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 7039 | const i::HeapEntry* from = ToInternal(this)->from(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7040 | return reinterpret_cast<const HeapGraphNode*>(from); |
| 7041 | } |
| 7042 | |
| 7043 | |
| 7044 | const HeapGraphNode* HeapGraphEdge::GetToNode() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7045 | const i::HeapEntry* to = ToInternal(this)->to(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7046 | return reinterpret_cast<const HeapGraphNode*>(to); |
| 7047 | } |
| 7048 | |
| 7049 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7050 | static i::HeapEntry* ToInternal(const HeapGraphNode* entry) { |
| 7051 | return const_cast<i::HeapEntry*>( |
| 7052 | reinterpret_cast<const i::HeapEntry*>(entry)); |
| 7053 | } |
| 7054 | |
| 7055 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7056 | HeapGraphNode::Type HeapGraphNode::GetType() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7057 | return static_cast<HeapGraphNode::Type>(ToInternal(this)->type()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7058 | } |
| 7059 | |
| 7060 | |
| 7061 | Handle<String> HeapGraphNode::GetName() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7062 | i::Isolate* isolate = i::Isolate::Current(); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 7063 | return ToApiHandle<String>( |
| 7064 | isolate->factory()->InternalizeUtf8String(ToInternal(this)->name())); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7065 | } |
| 7066 | |
| 7067 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7068 | SnapshotObjectId HeapGraphNode::GetId() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7069 | return ToInternal(this)->id(); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 7070 | } |
| 7071 | |
| 7072 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7073 | int HeapGraphNode::GetSelfSize() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7074 | return ToInternal(this)->self_size(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7075 | } |
| 7076 | |
| 7077 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7078 | int HeapGraphNode::GetChildrenCount() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7079 | return ToInternal(this)->children().length(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7080 | } |
| 7081 | |
| 7082 | |
| 7083 | const HeapGraphEdge* HeapGraphNode::GetChild(int index) const { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7084 | return reinterpret_cast<const HeapGraphEdge*>( |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 7085 | ToInternal(this)->children()[index]); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7086 | } |
| 7087 | |
| 7088 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7089 | static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) { |
| 7090 | return const_cast<i::HeapSnapshot*>( |
| 7091 | reinterpret_cast<const i::HeapSnapshot*>(snapshot)); |
| 7092 | } |
| 7093 | |
| 7094 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7095 | void HeapSnapshot::Delete() { |
| 7096 | i::Isolate* isolate = i::Isolate::Current(); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7097 | if (isolate->heap_profiler()->GetSnapshotsCount() > 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7098 | ToInternal(this)->Delete(); |
| 7099 | } else { |
| 7100 | // 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] | 7101 | isolate->heap_profiler()->DeleteAllSnapshots(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7102 | } |
| 7103 | } |
| 7104 | |
| 7105 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7106 | unsigned HeapSnapshot::GetUid() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7107 | return ToInternal(this)->uid(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7108 | } |
| 7109 | |
| 7110 | |
| 7111 | Handle<String> HeapSnapshot::GetTitle() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7112 | i::Isolate* isolate = i::Isolate::Current(); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 7113 | return ToApiHandle<String>( |
| 7114 | isolate->factory()->InternalizeUtf8String(ToInternal(this)->title())); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7115 | } |
| 7116 | |
| 7117 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 7118 | const HeapGraphNode* HeapSnapshot::GetRoot() const { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 7119 | return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7120 | } |
| 7121 | |
| 7122 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7123 | const HeapGraphNode* HeapSnapshot::GetNodeById(SnapshotObjectId id) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7124 | return reinterpret_cast<const HeapGraphNode*>( |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7125 | ToInternal(this)->GetEntryById(id)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7126 | } |
| 7127 | |
| 7128 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 7129 | int HeapSnapshot::GetNodesCount() const { |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 7130 | return ToInternal(this)->entries().length(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 7131 | } |
| 7132 | |
| 7133 | |
| 7134 | const HeapGraphNode* HeapSnapshot::GetNode(int index) const { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 7135 | return reinterpret_cast<const HeapGraphNode*>( |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 7136 | &ToInternal(this)->entries().at(index)); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 7137 | } |
| 7138 | |
| 7139 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7140 | SnapshotObjectId HeapSnapshot::GetMaxSnapshotJSObjectId() const { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7141 | return ToInternal(this)->max_snapshot_js_object_id(); |
| 7142 | } |
| 7143 | |
| 7144 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 7145 | void HeapSnapshot::Serialize(OutputStream* stream, |
| 7146 | HeapSnapshot::SerializationFormat format) const { |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 7147 | ApiCheck(format == kJSON, |
| 7148 | "v8::HeapSnapshot::Serialize", |
| 7149 | "Unknown serialization format"); |
| 7150 | ApiCheck(stream->GetOutputEncoding() == OutputStream::kAscii, |
| 7151 | "v8::HeapSnapshot::Serialize", |
| 7152 | "Unsupported output encoding"); |
| 7153 | ApiCheck(stream->GetChunkSize() > 0, |
| 7154 | "v8::HeapSnapshot::Serialize", |
| 7155 | "Invalid stream chunk size"); |
| 7156 | i::HeapSnapshotJSONSerializer serializer(ToInternal(this)); |
| 7157 | serializer.Serialize(stream); |
| 7158 | } |
| 7159 | |
| 7160 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7161 | int HeapProfiler::GetSnapshotCount() { |
| 7162 | return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7163 | } |
| 7164 | |
| 7165 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7166 | const HeapSnapshot* HeapProfiler::GetHeapSnapshot(int index) { |
| 7167 | return reinterpret_cast<const HeapSnapshot*>( |
| 7168 | reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7169 | } |
| 7170 | |
| 7171 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7172 | SnapshotObjectId HeapProfiler::GetObjectId(Handle<Value> value) { |
| 7173 | i::Handle<i::Object> obj = Utils::OpenHandle(*value); |
| 7174 | return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotObjectId(obj); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 7175 | } |
| 7176 | |
| 7177 | |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 7178 | Handle<Value> HeapProfiler::FindObjectById(SnapshotObjectId id) { |
| 7179 | i::Handle<i::Object> obj = |
| 7180 | reinterpret_cast<i::HeapProfiler*>(this)->FindHeapObjectById(id); |
| 7181 | if (obj.is_null()) return Local<Value>(); |
| 7182 | return Utils::ToLocal(obj); |
| 7183 | } |
| 7184 | |
| 7185 | |
| 7186 | void HeapProfiler::ClearObjectIds() { |
| 7187 | reinterpret_cast<i::HeapProfiler*>(this)->ClearHeapObjectMap(); |
| 7188 | } |
| 7189 | |
| 7190 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7191 | const HeapSnapshot* HeapProfiler::TakeHeapSnapshot( |
| 7192 | Handle<String> title, |
| 7193 | ActivityControl* control, |
| 7194 | ObjectNameResolver* resolver) { |
| 7195 | return reinterpret_cast<const HeapSnapshot*>( |
| 7196 | reinterpret_cast<i::HeapProfiler*>(this)->TakeSnapshot( |
| 7197 | *Utils::OpenHandle(*title), control, resolver)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 7198 | } |
| 7199 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 7200 | |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 7201 | void HeapProfiler::StartTrackingHeapObjects(bool track_allocations) { |
| 7202 | reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking( |
| 7203 | track_allocations); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 7204 | } |
| 7205 | |
| 7206 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7207 | void HeapProfiler::StopTrackingHeapObjects() { |
| 7208 | reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking(); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 7209 | } |
| 7210 | |
| 7211 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7212 | SnapshotObjectId HeapProfiler::GetHeapStats(OutputStream* stream) { |
| 7213 | return reinterpret_cast<i::HeapProfiler*>(this)->PushHeapObjectsStats(stream); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 7214 | } |
| 7215 | |
| 7216 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7217 | void HeapProfiler::DeleteAllHeapSnapshots() { |
| 7218 | reinterpret_cast<i::HeapProfiler*>(this)->DeleteAllSnapshots(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7219 | } |
| 7220 | |
| 7221 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7222 | void HeapProfiler::SetWrapperClassInfoProvider(uint16_t class_id, |
| 7223 | WrapperInfoCallback callback) { |
| 7224 | reinterpret_cast<i::HeapProfiler*>(this)->DefineWrapperClass(class_id, |
| 7225 | callback); |
| 7226 | } |
| 7227 | |
| 7228 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7229 | size_t HeapProfiler::GetProfilerMemorySize() { |
| 7230 | return reinterpret_cast<i::HeapProfiler*>(this)-> |
| 7231 | GetMemorySizeUsedByProfiler(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 7232 | } |
| 7233 | |
| 7234 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7235 | void HeapProfiler::SetRetainedObjectInfo(UniqueId id, |
| 7236 | RetainedObjectInfo* info) { |
| 7237 | reinterpret_cast<i::HeapProfiler*>(this)->SetRetainedObjectInfo(id, info); |
| 7238 | } |
| 7239 | |
| 7240 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7241 | v8::Testing::StressType internal::Testing::stress_type_ = |
| 7242 | v8::Testing::kStressTypeOpt; |
| 7243 | |
| 7244 | |
| 7245 | void Testing::SetStressRunType(Testing::StressType type) { |
| 7246 | internal::Testing::set_stress_type(type); |
| 7247 | } |
| 7248 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 7249 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7250 | int Testing::GetStressRuns() { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 7251 | if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7252 | #ifdef DEBUG |
| 7253 | // In debug mode the code runs much slower so stressing will only make two |
| 7254 | // runs. |
| 7255 | return 2; |
| 7256 | #else |
| 7257 | return 5; |
| 7258 | #endif |
| 7259 | } |
| 7260 | |
| 7261 | |
| 7262 | static void SetFlagsFromString(const char* flags) { |
| 7263 | V8::SetFlagsFromString(flags, i::StrLength(flags)); |
| 7264 | } |
| 7265 | |
| 7266 | |
| 7267 | void Testing::PrepareStressRun(int run) { |
| 7268 | static const char* kLazyOptimizations = |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 7269 | "--prepare-always-opt " |
| 7270 | "--max-inlined-source-size=999999 " |
| 7271 | "--max-inlined-nodes=999999 " |
| 7272 | "--max-inlined-nodes-cumulative=999999 " |
| 7273 | "--noalways-opt"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7274 | static const char* kForcedOptimizations = "--always-opt"; |
| 7275 | |
| 7276 | // If deoptimization stressed turn on frequent deoptimization. If no value |
| 7277 | // is spefified through --deopt-every-n-times use a default default value. |
| 7278 | static const char* kDeoptEvery13Times = "--deopt-every-n-times=13"; |
| 7279 | if (internal::Testing::stress_type() == Testing::kStressTypeDeopt && |
| 7280 | internal::FLAG_deopt_every_n_times == 0) { |
| 7281 | SetFlagsFromString(kDeoptEvery13Times); |
| 7282 | } |
| 7283 | |
| 7284 | #ifdef DEBUG |
| 7285 | // As stressing in debug mode only make two runs skip the deopt stressing |
| 7286 | // here. |
| 7287 | if (run == GetStressRuns() - 1) { |
| 7288 | SetFlagsFromString(kForcedOptimizations); |
| 7289 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7290 | SetFlagsFromString(kLazyOptimizations); |
| 7291 | } |
| 7292 | #else |
| 7293 | if (run == GetStressRuns() - 1) { |
| 7294 | SetFlagsFromString(kForcedOptimizations); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 7295 | } else if (run != GetStressRuns() - 2) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7296 | SetFlagsFromString(kLazyOptimizations); |
| 7297 | } |
| 7298 | #endif |
| 7299 | } |
| 7300 | |
| 7301 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7302 | // TODO(svenpanne) Deprecate this. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 7303 | void Testing::DeoptimizeAll() { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 7304 | i::Isolate* isolate = i::Isolate::Current(); |
| 7305 | i::HandleScope scope(isolate); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 7306 | internal::Deoptimizer::DeoptimizeAll(isolate); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 7307 | } |
| 7308 | |
| 7309 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7310 | namespace internal { |
| 7311 | |
| 7312 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7313 | void HandleScopeImplementer::FreeThreadResources() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7314 | Free(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7315 | } |
| 7316 | |
| 7317 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7318 | char* HandleScopeImplementer::ArchiveThread(char* storage) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 7319 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7320 | isolate_->handle_scope_data(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7321 | handle_scope_data_ = *current; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7322 | OS::MemCopy(storage, this, sizeof(*this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7323 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7324 | ResetAfterArchive(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7325 | current->Initialize(); |
| 7326 | |
| 7327 | return storage + ArchiveSpacePerThread(); |
| 7328 | } |
| 7329 | |
| 7330 | |
| 7331 | int HandleScopeImplementer::ArchiveSpacePerThread() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7332 | return sizeof(HandleScopeImplementer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7333 | } |
| 7334 | |
| 7335 | |
| 7336 | char* HandleScopeImplementer::RestoreThread(char* storage) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7337 | OS::MemCopy(this, storage, sizeof(*this)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7338 | *isolate_->handle_scope_data() = handle_scope_data_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7339 | return storage + ArchiveSpacePerThread(); |
| 7340 | } |
| 7341 | |
| 7342 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 7343 | void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7344 | #ifdef DEBUG |
| 7345 | bool found_block_before_deferred = false; |
| 7346 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7347 | // Iterate over all handles in the blocks except for the last. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7348 | for (int i = blocks()->length() - 2; i >= 0; --i) { |
| 7349 | Object** block = blocks()->at(i); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7350 | if (last_handle_before_deferred_block_ != NULL && |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 7351 | (last_handle_before_deferred_block_ <= &block[kHandleBlockSize]) && |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7352 | (last_handle_before_deferred_block_ >= block)) { |
| 7353 | v->VisitPointers(block, last_handle_before_deferred_block_); |
| 7354 | ASSERT(!found_block_before_deferred); |
| 7355 | #ifdef DEBUG |
| 7356 | found_block_before_deferred = true; |
| 7357 | #endif |
| 7358 | } else { |
| 7359 | v->VisitPointers(block, &block[kHandleBlockSize]); |
| 7360 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7361 | } |
| 7362 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7363 | ASSERT(last_handle_before_deferred_block_ == NULL || |
| 7364 | found_block_before_deferred); |
| 7365 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7366 | // Iterate over live handles in the last block (if any). |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7367 | if (!blocks()->is_empty()) { |
| 7368 | v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 7369 | } |
| 7370 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 7371 | List<Context*>* context_lists[2] = { &saved_contexts_, &entered_contexts_}; |
| 7372 | for (unsigned i = 0; i < ARRAY_SIZE(context_lists); i++) { |
| 7373 | if (context_lists[i]->is_empty()) continue; |
| 7374 | Object** start = reinterpret_cast<Object**>(&context_lists[i]->first()); |
| 7375 | v->VisitPointers(start, start + context_lists[i]->length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7376 | } |
| 7377 | } |
| 7378 | |
| 7379 | |
| 7380 | void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 7381 | v8::ImplementationUtilities::HandleScopeData* current = |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7382 | isolate_->handle_scope_data(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7383 | handle_scope_data_ = *current; |
| 7384 | IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7385 | } |
| 7386 | |
| 7387 | |
| 7388 | char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 7389 | HandleScopeImplementer* scope_implementer = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7390 | reinterpret_cast<HandleScopeImplementer*>(storage); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 7391 | scope_implementer->IterateThis(v); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7392 | return storage + ArchiveSpacePerThread(); |
| 7393 | } |
| 7394 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7395 | |
| 7396 | DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 7397 | DeferredHandles* deferred = |
| 7398 | new DeferredHandles(isolate()->handle_scope_data()->next, isolate()); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7399 | |
| 7400 | while (!blocks_.is_empty()) { |
| 7401 | Object** block_start = blocks_.last(); |
| 7402 | Object** block_limit = &block_start[kHandleBlockSize]; |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 7403 | // We should not need to check for SealHandleScope here. Assert this. |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7404 | ASSERT(prev_limit == block_limit || |
| 7405 | !(block_start <= prev_limit && prev_limit <= block_limit)); |
| 7406 | if (prev_limit == block_limit) break; |
| 7407 | deferred->blocks_.Add(blocks_.last()); |
| 7408 | blocks_.RemoveLast(); |
| 7409 | } |
| 7410 | |
| 7411 | // deferred->blocks_ now contains the blocks installed on the |
| 7412 | // HandleScope stack since BeginDeferredScope was called, but in |
| 7413 | // reverse order. |
| 7414 | |
| 7415 | ASSERT(prev_limit == NULL || !blocks_.is_empty()); |
| 7416 | |
| 7417 | ASSERT(!blocks_.is_empty() && prev_limit != NULL); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7418 | ASSERT(last_handle_before_deferred_block_ != NULL); |
| 7419 | last_handle_before_deferred_block_ = NULL; |
| 7420 | return deferred; |
| 7421 | } |
| 7422 | |
| 7423 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7424 | void HandleScopeImplementer::BeginDeferredScope() { |
| 7425 | ASSERT(last_handle_before_deferred_block_ == NULL); |
| 7426 | last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next; |
| 7427 | } |
| 7428 | |
| 7429 | |
| 7430 | DeferredHandles::~DeferredHandles() { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 7431 | isolate_->UnlinkDeferredHandles(this); |
| 7432 | |
| 7433 | for (int i = 0; i < blocks_.length(); i++) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 7434 | #ifdef ENABLE_HANDLE_ZAPPING |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 7435 | HandleScope::ZapRange(blocks_[i], &blocks_[i][kHandleBlockSize]); |
| 7436 | #endif |
| 7437 | isolate_->handle_scope_implementer()->ReturnBlock(blocks_[i]); |
| 7438 | } |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7439 | } |
| 7440 | |
| 7441 | |
| 7442 | void DeferredHandles::Iterate(ObjectVisitor* v) { |
| 7443 | ASSERT(!blocks_.is_empty()); |
| 7444 | |
| 7445 | ASSERT((first_block_limit_ >= blocks_.first()) && |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7446 | (first_block_limit_ <= &(blocks_.first())[kHandleBlockSize])); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 7447 | |
| 7448 | v->VisitPointers(blocks_.first(), first_block_limit_); |
| 7449 | |
| 7450 | for (int i = 1; i < blocks_.length(); i++) { |
| 7451 | v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
| 7452 | } |
| 7453 | } |
| 7454 | |
| 7455 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7456 | void InvokeAccessorGetterCallback( |
| 7457 | v8::Local<v8::String> property, |
| 7458 | const v8::PropertyCallbackInfo<v8::Value>& info, |
| 7459 | v8::AccessorGetterCallback getter) { |
| 7460 | // Leaving JavaScript. |
| 7461 | Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7462 | Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>( |
| 7463 | getter)); |
| 7464 | VMState<EXTERNAL> state(isolate); |
| 7465 | ExternalCallbackScope call_scope(isolate, getter_address); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 7466 | getter(property, info); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7467 | } |
| 7468 | |
| 7469 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7470 | void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info, |
| 7471 | v8::FunctionCallback callback) { |
| 7472 | Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7473 | Address callback_address = |
| 7474 | reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7475 | VMState<EXTERNAL> state(isolate); |
| 7476 | ExternalCallbackScope call_scope(isolate, callback_address); |
dslomov@chromium.org | 639bac0 | 2013-09-09 11:58:54 +0000 | [diff] [blame] | 7477 | callback(info); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7478 | } |
| 7479 | |
| 7480 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7481 | } } // namespace v8::internal |