danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +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 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "api.h" |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 31 | #include "debug.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "execution.h" |
| 33 | #include "factory.h" |
| 34 | #include "macro-assembler.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 35 | #include "objects.h" |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 36 | #include "objects-visiting.h" |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 37 | #include "platform.h" |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 38 | #include "scopeinfo.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 40 | namespace v8 { |
| 41 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
| 43 | |
| 44 | Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) { |
| 45 | ASSERT(0 <= size); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 46 | CALL_HEAP_FUNCTION( |
| 47 | isolate(), |
| 48 | isolate()->heap()->AllocateFixedArray(size, pretenure), |
| 49 | FixedArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 53 | Handle<FixedArray> Factory::NewFixedArrayWithHoles(int size, |
| 54 | PretenureFlag pretenure) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 55 | ASSERT(0 <= size); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 56 | CALL_HEAP_FUNCTION( |
| 57 | isolate(), |
| 58 | isolate()->heap()->AllocateFixedArrayWithHoles(size, pretenure), |
| 59 | FixedArray); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 63 | Handle<FixedDoubleArray> Factory::NewFixedDoubleArray(int size, |
| 64 | PretenureFlag pretenure) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 65 | ASSERT(0 <= size); |
| 66 | CALL_HEAP_FUNCTION( |
| 67 | isolate(), |
| 68 | isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 69 | FixedDoubleArray); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 73 | Handle<StringDictionary> Factory::NewStringDictionary(int at_least_space_for) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 74 | ASSERT(0 <= at_least_space_for); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 75 | CALL_HEAP_FUNCTION(isolate(), |
| 76 | StringDictionary::Allocate(at_least_space_for), |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 77 | StringDictionary); |
| 78 | } |
| 79 | |
| 80 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 81 | Handle<SeededNumberDictionary> Factory::NewSeededNumberDictionary( |
| 82 | int at_least_space_for) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 83 | ASSERT(0 <= at_least_space_for); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 84 | CALL_HEAP_FUNCTION(isolate(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 85 | SeededNumberDictionary::Allocate(at_least_space_for), |
| 86 | SeededNumberDictionary); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | Handle<UnseededNumberDictionary> Factory::NewUnseededNumberDictionary( |
| 91 | int at_least_space_for) { |
| 92 | ASSERT(0 <= at_least_space_for); |
| 93 | CALL_HEAP_FUNCTION(isolate(), |
| 94 | UnseededNumberDictionary::Allocate(at_least_space_for), |
| 95 | UnseededNumberDictionary); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 99 | Handle<ObjectHashSet> Factory::NewObjectHashSet(int at_least_space_for) { |
| 100 | ASSERT(0 <= at_least_space_for); |
| 101 | CALL_HEAP_FUNCTION(isolate(), |
| 102 | ObjectHashSet::Allocate(at_least_space_for), |
| 103 | ObjectHashSet); |
| 104 | } |
| 105 | |
| 106 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 107 | Handle<ObjectHashTable> Factory::NewObjectHashTable(int at_least_space_for) { |
| 108 | ASSERT(0 <= at_least_space_for); |
| 109 | CALL_HEAP_FUNCTION(isolate(), |
| 110 | ObjectHashTable::Allocate(at_least_space_for), |
| 111 | ObjectHashTable); |
| 112 | } |
| 113 | |
| 114 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 115 | Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors) { |
| 116 | ASSERT(0 <= number_of_descriptors); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 117 | CALL_HEAP_FUNCTION(isolate(), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 118 | DescriptorArray::Allocate(number_of_descriptors, |
| 119 | DescriptorArray::MAY_BE_SHARED), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 120 | DescriptorArray); |
| 121 | } |
| 122 | |
| 123 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 124 | Handle<DeoptimizationInputData> Factory::NewDeoptimizationInputData( |
| 125 | int deopt_entry_count, |
| 126 | PretenureFlag pretenure) { |
| 127 | ASSERT(deopt_entry_count > 0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 128 | CALL_HEAP_FUNCTION(isolate(), |
| 129 | DeoptimizationInputData::Allocate(deopt_entry_count, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 130 | pretenure), |
| 131 | DeoptimizationInputData); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | Handle<DeoptimizationOutputData> Factory::NewDeoptimizationOutputData( |
| 136 | int deopt_entry_count, |
| 137 | PretenureFlag pretenure) { |
| 138 | ASSERT(deopt_entry_count > 0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 139 | CALL_HEAP_FUNCTION(isolate(), |
| 140 | DeoptimizationOutputData::Allocate(deopt_entry_count, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 141 | pretenure), |
| 142 | DeoptimizationOutputData); |
| 143 | } |
| 144 | |
| 145 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 146 | Handle<AccessorPair> Factory::NewAccessorPair() { |
| 147 | CALL_HEAP_FUNCTION(isolate(), |
| 148 | isolate()->heap()->AllocateAccessorPair(), |
| 149 | AccessorPair); |
| 150 | } |
| 151 | |
| 152 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 153 | Handle<TypeFeedbackInfo> Factory::NewTypeFeedbackInfo() { |
| 154 | CALL_HEAP_FUNCTION(isolate(), |
| 155 | isolate()->heap()->AllocateTypeFeedbackInfo(), |
| 156 | TypeFeedbackInfo); |
| 157 | } |
| 158 | |
| 159 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 160 | // Symbols are created in the old generation (data space). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 161 | Handle<String> Factory::LookupSymbol(Vector<const char> string) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 162 | CALL_HEAP_FUNCTION(isolate(), |
| 163 | isolate()->heap()->LookupSymbol(string), |
| 164 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 165 | } |
| 166 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 167 | // Symbols are created in the old generation (data space). |
| 168 | Handle<String> Factory::LookupSymbol(Handle<String> string) { |
| 169 | CALL_HEAP_FUNCTION(isolate(), |
| 170 | isolate()->heap()->LookupSymbol(*string), |
| 171 | String); |
| 172 | } |
| 173 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 174 | Handle<String> Factory::LookupAsciiSymbol(Vector<const char> string) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 175 | CALL_HEAP_FUNCTION(isolate(), |
| 176 | isolate()->heap()->LookupAsciiSymbol(string), |
| 177 | String); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 178 | } |
| 179 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 180 | |
| 181 | Handle<String> Factory::LookupAsciiSymbol(Handle<SeqAsciiString> string, |
| 182 | int from, |
| 183 | int length) { |
| 184 | CALL_HEAP_FUNCTION(isolate(), |
| 185 | isolate()->heap()->LookupAsciiSymbol(string, |
| 186 | from, |
| 187 | length), |
| 188 | String); |
| 189 | } |
| 190 | |
| 191 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 192 | Handle<String> Factory::LookupTwoByteSymbol(Vector<const uc16> string) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 193 | CALL_HEAP_FUNCTION(isolate(), |
| 194 | isolate()->heap()->LookupTwoByteSymbol(string), |
| 195 | String); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 196 | } |
| 197 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 198 | |
| 199 | Handle<String> Factory::NewStringFromAscii(Vector<const char> string, |
| 200 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 201 | CALL_HEAP_FUNCTION( |
| 202 | isolate(), |
| 203 | isolate()->heap()->AllocateStringFromAscii(string, pretenure), |
| 204 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | Handle<String> Factory::NewStringFromUtf8(Vector<const char> string, |
| 208 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 209 | CALL_HEAP_FUNCTION( |
| 210 | isolate(), |
| 211 | isolate()->heap()->AllocateStringFromUtf8(string, pretenure), |
| 212 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 216 | Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string, |
| 217 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 218 | CALL_HEAP_FUNCTION( |
| 219 | isolate(), |
| 220 | isolate()->heap()->AllocateStringFromTwoByte(string, pretenure), |
| 221 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 225 | Handle<SeqAsciiString> Factory::NewRawAsciiString(int length, |
| 226 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 227 | CALL_HEAP_FUNCTION( |
| 228 | isolate(), |
| 229 | isolate()->heap()->AllocateRawAsciiString(length, pretenure), |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 230 | SeqAsciiString); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 234 | Handle<SeqTwoByteString> Factory::NewRawTwoByteString(int length, |
| 235 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 236 | CALL_HEAP_FUNCTION( |
| 237 | isolate(), |
| 238 | isolate()->heap()->AllocateRawTwoByteString(length, pretenure), |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 239 | SeqTwoByteString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | |
| 243 | Handle<String> Factory::NewConsString(Handle<String> first, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 244 | Handle<String> second) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 245 | CALL_HEAP_FUNCTION(isolate(), |
| 246 | isolate()->heap()->AllocateConsString(*first, *second), |
| 247 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 251 | Handle<String> Factory::NewSubString(Handle<String> str, |
| 252 | int begin, |
| 253 | int end) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 254 | CALL_HEAP_FUNCTION(isolate(), |
| 255 | str->SubString(begin, end), |
| 256 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 260 | Handle<String> Factory::NewProperSubString(Handle<String> str, |
| 261 | int begin, |
| 262 | int end) { |
| 263 | ASSERT(begin > 0 || end < str->length()); |
| 264 | CALL_HEAP_FUNCTION(isolate(), |
| 265 | isolate()->heap()->AllocateSubString(*str, begin, end), |
| 266 | String); |
| 267 | } |
| 268 | |
| 269 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 270 | Handle<String> Factory::NewExternalStringFromAscii( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 271 | const ExternalAsciiString::Resource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 272 | CALL_HEAP_FUNCTION( |
| 273 | isolate(), |
| 274 | isolate()->heap()->AllocateExternalStringFromAscii(resource), |
| 275 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | |
| 279 | Handle<String> Factory::NewExternalStringFromTwoByte( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 280 | const ExternalTwoByteString::Resource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 281 | CALL_HEAP_FUNCTION( |
| 282 | isolate(), |
| 283 | isolate()->heap()->AllocateExternalStringFromTwoByte(resource), |
| 284 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | |
| 288 | Handle<Context> Factory::NewGlobalContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 289 | CALL_HEAP_FUNCTION( |
| 290 | isolate(), |
| 291 | isolate()->heap()->AllocateGlobalContext(), |
| 292 | Context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 296 | Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 297 | CALL_HEAP_FUNCTION( |
| 298 | isolate(), |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 299 | isolate()->heap()->AllocateModuleContext(*scope_info), |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 300 | Context); |
| 301 | } |
| 302 | |
| 303 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 304 | Handle<Context> Factory::NewFunctionContext(int length, |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 305 | Handle<JSFunction> function) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 306 | CALL_HEAP_FUNCTION( |
| 307 | isolate(), |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 308 | isolate()->heap()->AllocateFunctionContext(length, *function), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 309 | Context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 313 | Handle<Context> Factory::NewCatchContext(Handle<JSFunction> function, |
| 314 | Handle<Context> previous, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 315 | Handle<String> name, |
| 316 | Handle<Object> thrown_object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 317 | CALL_HEAP_FUNCTION( |
| 318 | isolate(), |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 319 | isolate()->heap()->AllocateCatchContext(*function, |
| 320 | *previous, |
| 321 | *name, |
| 322 | *thrown_object), |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 323 | Context); |
| 324 | } |
| 325 | |
| 326 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 327 | Handle<Context> Factory::NewWithContext(Handle<JSFunction> function, |
| 328 | Handle<Context> previous, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 329 | Handle<JSObject> extension) { |
| 330 | CALL_HEAP_FUNCTION( |
| 331 | isolate(), |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 332 | isolate()->heap()->AllocateWithContext(*function, *previous, *extension), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 333 | Context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 337 | Handle<Context> Factory::NewBlockContext(Handle<JSFunction> function, |
| 338 | Handle<Context> previous, |
| 339 | Handle<ScopeInfo> scope_info) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 340 | CALL_HEAP_FUNCTION( |
| 341 | isolate(), |
| 342 | isolate()->heap()->AllocateBlockContext(*function, |
| 343 | *previous, |
| 344 | *scope_info), |
| 345 | Context); |
| 346 | } |
| 347 | |
| 348 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | Handle<Struct> Factory::NewStruct(InstanceType type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 350 | CALL_HEAP_FUNCTION( |
| 351 | isolate(), |
| 352 | isolate()->heap()->AllocateStruct(type), |
| 353 | Struct); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | |
| 357 | Handle<AccessorInfo> Factory::NewAccessorInfo() { |
| 358 | Handle<AccessorInfo> info = |
| 359 | Handle<AccessorInfo>::cast(NewStruct(ACCESSOR_INFO_TYPE)); |
| 360 | info->set_flag(0); // Must clear the flag, it was initialized as undefined. |
| 361 | return info; |
| 362 | } |
| 363 | |
| 364 | |
| 365 | Handle<Script> Factory::NewScript(Handle<String> source) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 366 | // Generate id for this script. |
| 367 | int id; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 368 | Heap* heap = isolate()->heap(); |
| 369 | if (heap->last_script_id()->IsUndefined()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 370 | // Script ids start from one. |
| 371 | id = 1; |
| 372 | } else { |
| 373 | // Increment id, wrap when positive smi is exhausted. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 374 | id = Smi::cast(heap->last_script_id())->value(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 375 | id++; |
| 376 | if (!Smi::IsValid(id)) { |
| 377 | id = 0; |
| 378 | } |
| 379 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 380 | heap->SetLastScriptId(Smi::FromInt(id)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 381 | |
| 382 | // Create and initialize script object. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 383 | Handle<Foreign> wrapper = NewForeign(0, TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 384 | Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE)); |
| 385 | script->set_source(*source); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 386 | script->set_name(heap->undefined_value()); |
| 387 | script->set_id(heap->last_script_id()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 388 | script->set_line_offset(Smi::FromInt(0)); |
| 389 | script->set_column_offset(Smi::FromInt(0)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 390 | script->set_data(heap->undefined_value()); |
| 391 | script->set_context_data(heap->undefined_value()); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 392 | script->set_type(Smi::FromInt(Script::TYPE_NORMAL)); |
| 393 | script->set_compilation_type(Smi::FromInt(Script::COMPILATION_TYPE_HOST)); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 394 | script->set_compilation_state( |
| 395 | Smi::FromInt(Script::COMPILATION_STATE_INITIAL)); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 396 | script->set_wrapper(*wrapper); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 397 | script->set_line_ends(heap->undefined_value()); |
| 398 | script->set_eval_from_shared(heap->undefined_value()); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 399 | script->set_eval_from_instructions_offset(Smi::FromInt(0)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 400 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 401 | return script; |
| 402 | } |
| 403 | |
| 404 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 405 | Handle<Foreign> Factory::NewForeign(Address addr, PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 406 | CALL_HEAP_FUNCTION(isolate(), |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 407 | isolate()->heap()->AllocateForeign(addr, pretenure), |
| 408 | Foreign); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 412 | Handle<Foreign> Factory::NewForeign(const AccessorDescriptor* desc) { |
| 413 | return NewForeign((Address) desc, TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 417 | Handle<ByteArray> Factory::NewByteArray(int length, PretenureFlag pretenure) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 418 | ASSERT(0 <= length); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 419 | CALL_HEAP_FUNCTION( |
| 420 | isolate(), |
| 421 | isolate()->heap()->AllocateByteArray(length, pretenure), |
| 422 | ByteArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 426 | Handle<ExternalArray> Factory::NewExternalArray(int length, |
| 427 | ExternalArrayType array_type, |
| 428 | void* external_pointer, |
| 429 | PretenureFlag pretenure) { |
| 430 | ASSERT(0 <= length); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 431 | CALL_HEAP_FUNCTION( |
| 432 | isolate(), |
| 433 | isolate()->heap()->AllocateExternalArray(length, |
| 434 | array_type, |
| 435 | external_pointer, |
| 436 | pretenure), |
| 437 | ExternalArray); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 441 | Handle<JSGlobalPropertyCell> Factory::NewJSGlobalPropertyCell( |
| 442 | Handle<Object> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 443 | CALL_HEAP_FUNCTION( |
| 444 | isolate(), |
| 445 | isolate()->heap()->AllocateJSGlobalPropertyCell(*value), |
| 446 | JSGlobalPropertyCell); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 450 | Handle<Map> Factory::NewMap(InstanceType type, |
| 451 | int instance_size, |
| 452 | ElementsKind elements_kind) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 453 | CALL_HEAP_FUNCTION( |
| 454 | isolate(), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 455 | isolate()->heap()->AllocateMap(type, instance_size, elements_kind), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 456 | Map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | |
| 460 | Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 461 | CALL_HEAP_FUNCTION( |
| 462 | isolate(), |
| 463 | isolate()->heap()->AllocateFunctionPrototype(*function), |
| 464 | JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame^] | 468 | Handle<Map> Factory::CopyWithPreallocatedFieldDescriptors(Handle<Map> src) { |
| 469 | CALL_HEAP_FUNCTION( |
| 470 | isolate(), src->CopyWithPreallocatedFieldDescriptors(), Map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 474 | Handle<Map> Factory::CopyMap(Handle<Map> src, |
| 475 | int extra_inobject_properties) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame^] | 476 | Handle<Map> copy = CopyWithPreallocatedFieldDescriptors(src); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 477 | // Check that we do not overflow the instance size when adding the |
| 478 | // extra inobject properties. |
| 479 | int instance_size_delta = extra_inobject_properties * kPointerSize; |
| 480 | int max_instance_size_delta = |
| 481 | JSObject::kMaxInstanceSize - copy->instance_size(); |
| 482 | if (instance_size_delta > max_instance_size_delta) { |
| 483 | // If the instance size overflows, we allocate as many properties |
| 484 | // as we can as inobject properties. |
| 485 | instance_size_delta = max_instance_size_delta; |
| 486 | extra_inobject_properties = max_instance_size_delta >> kPointerSizeLog2; |
| 487 | } |
| 488 | // Adjust the map with the extra inobject properties. |
| 489 | int inobject_properties = |
| 490 | copy->inobject_properties() + extra_inobject_properties; |
| 491 | copy->set_inobject_properties(inobject_properties); |
| 492 | copy->set_unused_property_fields(inobject_properties); |
| 493 | copy->set_instance_size(copy->instance_size() + instance_size_delta); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 494 | copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 495 | return copy; |
| 496 | } |
| 497 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 498 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 499 | Handle<Map> Factory::CopyMapDropTransitions(Handle<Map> src) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 500 | CALL_HEAP_FUNCTION(isolate(), |
| 501 | src->CopyDropTransitions(DescriptorArray::MAY_BE_SHARED), |
| 502 | Map); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 506 | Handle<Map> Factory::GetElementsTransitionMap( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 507 | Handle<JSObject> src, |
| 508 | ElementsKind elements_kind) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 509 | Isolate* i = isolate(); |
| 510 | CALL_HEAP_FUNCTION(i, |
| 511 | src->GetElementsTransitionMap(i, elements_kind), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 512 | Map); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 516 | Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 517 | CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 521 | Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray( |
| 522 | Handle<FixedDoubleArray> array) { |
| 523 | CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray); |
| 524 | } |
| 525 | |
| 526 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 527 | Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo( |
| 528 | Handle<SharedFunctionInfo> function_info, |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 529 | Handle<Map> function_map, |
| 530 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 531 | CALL_HEAP_FUNCTION( |
| 532 | isolate(), |
| 533 | isolate()->heap()->AllocateFunction(*function_map, |
| 534 | *function_info, |
| 535 | isolate()->heap()->the_hole_value(), |
| 536 | pretenure), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 537 | JSFunction); |
| 538 | } |
| 539 | |
| 540 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 541 | Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
| 542 | Handle<SharedFunctionInfo> function_info, |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 543 | Handle<Context> context, |
| 544 | PretenureFlag pretenure) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 545 | Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 546 | function_info, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 547 | function_info->is_classic_mode() |
| 548 | ? isolate()->function_map() |
| 549 | : isolate()->strict_mode_function_map(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 550 | pretenure); |
| 551 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 552 | if (function_info->ic_age() != isolate()->heap()->global_ic_age()) { |
| 553 | function_info->ResetForNewContext(isolate()->heap()->global_ic_age()); |
| 554 | } |
| 555 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 556 | result->set_context(*context); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 557 | |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 558 | int index = function_info->SearchOptimizedCodeMap(context->global_context()); |
| 559 | if (!function_info->bound() && index < 0) { |
| 560 | int number_of_literals = function_info->num_literals(); |
| 561 | Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure); |
| 562 | if (number_of_literals > 0) { |
| 563 | // Store the global context in the literals array prefix. This |
| 564 | // context will be used when creating object, regexp and array |
| 565 | // literals in this function. |
| 566 | literals->set(JSFunction::kLiteralGlobalContextIndex, |
| 567 | context->global_context()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 568 | } |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 569 | result->set_literals(*literals); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 570 | } |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 571 | |
| 572 | if (index > 0) { |
| 573 | // Caching of optimized code enabled and optimized code found. |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 574 | function_info->InstallFromOptimizedCodeMap(*result, index); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 575 | return result; |
| 576 | } |
| 577 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 578 | if (V8::UseCrankshaft() && |
| 579 | FLAG_always_opt && |
| 580 | result->is_compiled() && |
| 581 | !function_info->is_toplevel() && |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 582 | function_info->allows_lazy_compilation() && |
| 583 | !function_info->optimization_disabled()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 584 | result->MarkForLazyRecompilation(); |
| 585 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 586 | return result; |
| 587 | } |
| 588 | |
| 589 | |
| 590 | Handle<Object> Factory::NewNumber(double value, |
| 591 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 592 | CALL_HEAP_FUNCTION( |
| 593 | isolate(), |
| 594 | isolate()->heap()->NumberFromDouble(value, pretenure), Object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 598 | Handle<Object> Factory::NewNumberFromInt(int32_t value, |
| 599 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 600 | CALL_HEAP_FUNCTION( |
| 601 | isolate(), |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 602 | isolate()->heap()->NumberFromInt32(value, pretenure), Object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 606 | Handle<Object> Factory::NewNumberFromUint(uint32_t value, |
| 607 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 608 | CALL_HEAP_FUNCTION( |
| 609 | isolate(), |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 610 | isolate()->heap()->NumberFromUint32(value, pretenure), Object); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 614 | Handle<JSObject> Factory::NewNeanderObject() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 615 | CALL_HEAP_FUNCTION( |
| 616 | isolate(), |
| 617 | isolate()->heap()->AllocateJSObjectFromMap( |
| 618 | isolate()->heap()->neander_map()), |
| 619 | JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | |
| 623 | Handle<Object> Factory::NewTypeError(const char* type, |
| 624 | Vector< Handle<Object> > args) { |
| 625 | return NewError("MakeTypeError", type, args); |
| 626 | } |
| 627 | |
| 628 | |
| 629 | Handle<Object> Factory::NewTypeError(Handle<String> message) { |
| 630 | return NewError("$TypeError", message); |
| 631 | } |
| 632 | |
| 633 | |
| 634 | Handle<Object> Factory::NewRangeError(const char* type, |
| 635 | Vector< Handle<Object> > args) { |
| 636 | return NewError("MakeRangeError", type, args); |
| 637 | } |
| 638 | |
| 639 | |
| 640 | Handle<Object> Factory::NewRangeError(Handle<String> message) { |
| 641 | return NewError("$RangeError", message); |
| 642 | } |
| 643 | |
| 644 | |
| 645 | Handle<Object> Factory::NewSyntaxError(const char* type, Handle<JSArray> args) { |
| 646 | return NewError("MakeSyntaxError", type, args); |
| 647 | } |
| 648 | |
| 649 | |
| 650 | Handle<Object> Factory::NewSyntaxError(Handle<String> message) { |
| 651 | return NewError("$SyntaxError", message); |
| 652 | } |
| 653 | |
| 654 | |
| 655 | Handle<Object> Factory::NewReferenceError(const char* type, |
| 656 | Vector< Handle<Object> > args) { |
| 657 | return NewError("MakeReferenceError", type, args); |
| 658 | } |
| 659 | |
| 660 | |
| 661 | Handle<Object> Factory::NewReferenceError(Handle<String> message) { |
| 662 | return NewError("$ReferenceError", message); |
| 663 | } |
| 664 | |
| 665 | |
| 666 | Handle<Object> Factory::NewError(const char* maker, const char* type, |
| 667 | Vector< Handle<Object> > args) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 668 | v8::HandleScope scope; // Instantiate a closeable HandleScope for EscapeFrom. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 669 | Handle<FixedArray> array = NewFixedArray(args.length()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 670 | for (int i = 0; i < args.length(); i++) { |
| 671 | array->set(i, *args[i]); |
| 672 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 673 | Handle<JSArray> object = NewJSArrayWithElements(array); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 674 | Handle<Object> result = NewError(maker, type, object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 675 | return result.EscapeFrom(&scope); |
| 676 | } |
| 677 | |
| 678 | |
| 679 | Handle<Object> Factory::NewEvalError(const char* type, |
| 680 | Vector< Handle<Object> > args) { |
| 681 | return NewError("MakeEvalError", type, args); |
| 682 | } |
| 683 | |
| 684 | |
| 685 | Handle<Object> Factory::NewError(const char* type, |
| 686 | Vector< Handle<Object> > args) { |
| 687 | return NewError("MakeError", type, args); |
| 688 | } |
| 689 | |
| 690 | |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 691 | Handle<String> Factory::EmergencyNewError(const char* type, |
| 692 | Handle<JSArray> args) { |
| 693 | const int kBufferSize = 1000; |
| 694 | char buffer[kBufferSize]; |
| 695 | size_t space = kBufferSize; |
| 696 | char* p = &buffer[0]; |
| 697 | |
| 698 | Vector<char> v(buffer, kBufferSize); |
| 699 | OS::StrNCpy(v, type, space); |
| 700 | space -= Min(space, strlen(type)); |
| 701 | p = &buffer[kBufferSize] - space; |
| 702 | |
| 703 | for (unsigned i = 0; i < ARRAY_SIZE(args); i++) { |
| 704 | if (space > 0) { |
| 705 | *p++ = ' '; |
| 706 | space--; |
| 707 | if (space > 0) { |
| 708 | MaybeObject* maybe_arg = args->GetElement(i); |
| 709 | Handle<String> arg_str(reinterpret_cast<String*>(maybe_arg)); |
| 710 | const char* arg = *arg_str->ToCString(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 711 | Vector<char> v2(p, static_cast<int>(space)); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 712 | OS::StrNCpy(v2, arg, space); |
| 713 | space -= Min(space, strlen(arg)); |
| 714 | p = &buffer[kBufferSize] - space; |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | if (space > 0) { |
| 719 | *p = '\0'; |
| 720 | } else { |
| 721 | buffer[kBufferSize - 1] = '\0'; |
| 722 | } |
| 723 | Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED); |
| 724 | return error_string; |
| 725 | } |
| 726 | |
| 727 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 728 | Handle<Object> Factory::NewError(const char* maker, |
| 729 | const char* type, |
| 730 | Handle<JSArray> args) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 731 | Handle<String> make_str = LookupAsciiSymbol(maker); |
| 732 | Handle<Object> fun_obj( |
| 733 | isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 734 | // If the builtins haven't been properly configured yet this error |
| 735 | // constructor may not have been defined. Bail out. |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 736 | if (!fun_obj->IsJSFunction()) { |
| 737 | return EmergencyNewError(type, args); |
| 738 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 739 | Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 740 | Handle<Object> type_obj = LookupAsciiSymbol(type); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 741 | Handle<Object> argv[] = { type_obj, args }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 742 | |
| 743 | // Invoke the JavaScript factory method. If an exception is thrown while |
| 744 | // running the factory method, use the exception as the result. |
| 745 | bool caught_exception; |
| 746 | Handle<Object> result = Execution::TryCall(fun, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 747 | isolate()->js_builtins_object(), |
| 748 | ARRAY_SIZE(argv), |
| 749 | argv, |
| 750 | &caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 751 | return result; |
| 752 | } |
| 753 | |
| 754 | |
| 755 | Handle<Object> Factory::NewError(Handle<String> message) { |
| 756 | return NewError("$Error", message); |
| 757 | } |
| 758 | |
| 759 | |
| 760 | Handle<Object> Factory::NewError(const char* constructor, |
| 761 | Handle<String> message) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 762 | Handle<String> constr = LookupAsciiSymbol(constructor); |
| 763 | Handle<JSFunction> fun = Handle<JSFunction>( |
| 764 | JSFunction::cast(isolate()->js_builtins_object()-> |
| 765 | GetPropertyNoExceptionThrown(*constr))); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 766 | Handle<Object> argv[] = { message }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 767 | |
| 768 | // Invoke the JavaScript factory method. If an exception is thrown while |
| 769 | // running the factory method, use the exception as the result. |
| 770 | bool caught_exception; |
| 771 | Handle<Object> result = Execution::TryCall(fun, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 772 | isolate()->js_builtins_object(), |
| 773 | ARRAY_SIZE(argv), |
| 774 | argv, |
| 775 | &caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 776 | return result; |
| 777 | } |
| 778 | |
| 779 | |
| 780 | Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
| 781 | InstanceType type, |
| 782 | int instance_size, |
| 783 | Handle<Code> code, |
| 784 | bool force_initial_map) { |
| 785 | // Allocate the function |
| 786 | Handle<JSFunction> function = NewFunction(name, the_hole_value()); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 787 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 788 | // Set up the code pointer in both the shared function info and in |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 789 | // the function itself. |
| 790 | function->shared()->set_code(*code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 791 | function->set_code(*code); |
| 792 | |
| 793 | if (force_initial_map || |
| 794 | type != JS_OBJECT_TYPE || |
| 795 | instance_size != JSObject::kHeaderSize) { |
| 796 | Handle<Map> initial_map = NewMap(type, instance_size); |
| 797 | Handle<JSObject> prototype = NewFunctionPrototype(function); |
| 798 | initial_map->set_prototype(*prototype); |
| 799 | function->set_initial_map(*initial_map); |
| 800 | initial_map->set_constructor(*function); |
| 801 | } else { |
| 802 | ASSERT(!function->has_initial_map()); |
| 803 | ASSERT(!function->has_prototype()); |
| 804 | } |
| 805 | |
| 806 | return function; |
| 807 | } |
| 808 | |
| 809 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 810 | Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name, |
| 811 | InstanceType type, |
| 812 | int instance_size, |
| 813 | Handle<JSObject> prototype, |
| 814 | Handle<Code> code, |
| 815 | bool force_initial_map) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 816 | // Allocate the function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 817 | Handle<JSFunction> function = NewFunction(name, prototype); |
| 818 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 819 | // Set up the code pointer in both the shared function info and in |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 820 | // the function itself. |
| 821 | function->shared()->set_code(*code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 822 | function->set_code(*code); |
| 823 | |
| 824 | if (force_initial_map || |
| 825 | type != JS_OBJECT_TYPE || |
| 826 | instance_size != JSObject::kHeaderSize) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 827 | Handle<Map> initial_map = NewMap(type, |
| 828 | instance_size, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 829 | GetInitialFastElementsKind()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 830 | function->set_initial_map(*initial_map); |
| 831 | initial_map->set_constructor(*function); |
| 832 | } |
| 833 | |
| 834 | // Set function.prototype and give the prototype a constructor |
| 835 | // property that refers to the function. |
| 836 | SetPrototypeProperty(function, prototype); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 837 | // Currently safe because it is only invoked from Genesis. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 838 | CHECK_NOT_EMPTY_HANDLE(isolate(), |
| 839 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 840 | prototype, constructor_symbol(), |
| 841 | function, DONT_ENUM)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 842 | return function; |
| 843 | } |
| 844 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 845 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 846 | Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name, |
| 847 | Handle<Code> code) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 848 | Handle<JSFunction> function = NewFunctionWithoutPrototype(name, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 849 | CLASSIC_MODE); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 850 | function->shared()->set_code(*code); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 851 | function->set_code(*code); |
| 852 | ASSERT(!function->has_initial_map()); |
| 853 | ASSERT(!function->has_prototype()); |
| 854 | return function; |
| 855 | } |
| 856 | |
| 857 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 858 | Handle<ScopeInfo> Factory::NewScopeInfo(int length) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 859 | CALL_HEAP_FUNCTION( |
| 860 | isolate(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 861 | isolate()->heap()->AllocateScopeInfo(length), |
| 862 | ScopeInfo); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 866 | Handle<Code> Factory::NewCode(const CodeDesc& desc, |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 867 | Code::Flags flags, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 868 | Handle<Object> self_ref, |
| 869 | bool immovable) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 870 | CALL_HEAP_FUNCTION(isolate(), |
| 871 | isolate()->heap()->CreateCode( |
| 872 | desc, flags, self_ref, immovable), |
| 873 | Code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | |
| 877 | Handle<Code> Factory::CopyCode(Handle<Code> code) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 878 | CALL_HEAP_FUNCTION(isolate(), |
| 879 | isolate()->heap()->CopyCode(*code), |
| 880 | Code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 884 | Handle<Code> Factory::CopyCode(Handle<Code> code, Vector<byte> reloc_info) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 885 | CALL_HEAP_FUNCTION(isolate(), |
| 886 | isolate()->heap()->CopyCode(*code, reloc_info), |
| 887 | Code); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 891 | MUST_USE_RESULT static inline MaybeObject* DoCopyInsert( |
| 892 | DescriptorArray* array, |
| 893 | String* key, |
| 894 | Object* value, |
| 895 | PropertyAttributes attributes) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame^] | 896 | CallbacksDescriptor desc(key, value, attributes, 0); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 897 | MaybeObject* obj = array->CopyInsert(&desc); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 898 | return obj; |
| 899 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 900 | |
| 901 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 902 | // Allocate the new array. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 903 | Handle<DescriptorArray> Factory::CopyAppendForeignDescriptor( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 904 | Handle<DescriptorArray> array, |
| 905 | Handle<String> key, |
| 906 | Handle<Object> value, |
| 907 | PropertyAttributes attributes) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 908 | CALL_HEAP_FUNCTION(isolate(), |
| 909 | DoCopyInsert(*array, *key, *value, attributes), |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 910 | DescriptorArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 911 | } |
| 912 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 913 | |
| 914 | Handle<String> Factory::SymbolFromString(Handle<String> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 915 | CALL_HEAP_FUNCTION(isolate(), |
| 916 | isolate()->heap()->LookupSymbol(*value), String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | |
| 920 | Handle<DescriptorArray> Factory::CopyAppendCallbackDescriptors( |
| 921 | Handle<DescriptorArray> array, |
| 922 | Handle<Object> descriptors) { |
| 923 | v8::NeanderArray callbacks(descriptors); |
| 924 | int nof_callbacks = callbacks.length(); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 925 | int descriptor_count = array->number_of_descriptors(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 926 | Handle<DescriptorArray> result = |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 927 | NewDescriptorArray(descriptor_count + nof_callbacks); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 928 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 929 | // Ensure that marking will not progress and change color of objects. |
| 930 | DescriptorArray::WhitenessWitness witness(*result); |
| 931 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 932 | // Copy the descriptors from the array. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 933 | for (int i = 0; i < descriptor_count; i++) { |
| 934 | DescriptorArray::CopyFrom(result, i, array, i, witness); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 935 | } |
| 936 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 937 | // Fill in new callback descriptors. Process the callbacks from |
| 938 | // back to front so that the last callback with a given name takes |
| 939 | // precedence over previously added callbacks with that name. |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame^] | 940 | int added_descriptor_count = descriptor_count; |
| 941 | int next_enum = array->NextEnumerationIndex(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 942 | for (int i = nof_callbacks - 1; i >= 0; i--) { |
| 943 | Handle<AccessorInfo> entry = |
| 944 | Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i))); |
| 945 | // Ensure the key is a symbol before writing into the instance descriptor. |
| 946 | Handle<String> key = |
| 947 | SymbolFromString(Handle<String>(String::cast(entry->name()))); |
| 948 | // Check if a descriptor with this name already exists before writing. |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame^] | 949 | if (LinearSearch(*result, EXPECT_UNSORTED, *key, added_descriptor_count) == |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 950 | DescriptorArray::kNotFound) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame^] | 951 | CallbacksDescriptor desc(*key, |
| 952 | *entry, |
| 953 | entry->property_attributes(), |
| 954 | next_enum++); |
| 955 | result->Set(added_descriptor_count, &desc, witness); |
| 956 | added_descriptor_count++; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame^] | 960 | // Return the old descriptor array if there were no new elements. |
| 961 | if (added_descriptor_count == descriptor_count) return array; |
| 962 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 963 | // If duplicates were detected, allocate a result of the right size |
| 964 | // and transfer the elements. |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame^] | 965 | if (added_descriptor_count < result->length()) { |
| 966 | Handle<DescriptorArray> new_result = |
| 967 | NewDescriptorArray(added_descriptor_count); |
| 968 | for (int i = 0; i < added_descriptor_count; i++) { |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 969 | DescriptorArray::CopyFrom(new_result, i, result, i, witness); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 970 | } |
| 971 | result = new_result; |
| 972 | } |
| 973 | |
| 974 | // Sort the result before returning. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 975 | result->Sort(witness); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame^] | 976 | ASSERT(result->NextEnumerationIndex() == next_enum); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 977 | return result; |
| 978 | } |
| 979 | |
| 980 | |
| 981 | Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, |
| 982 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 983 | CALL_HEAP_FUNCTION( |
| 984 | isolate(), |
| 985 | isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 989 | Handle<JSModule> Factory::NewJSModule(Handle<Context> context, |
| 990 | Handle<ScopeInfo> scope_info) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 991 | CALL_HEAP_FUNCTION( |
| 992 | isolate(), |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 993 | isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 997 | Handle<GlobalObject> Factory::NewGlobalObject( |
| 998 | Handle<JSFunction> constructor) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 999 | CALL_HEAP_FUNCTION(isolate(), |
| 1000 | isolate()->heap()->AllocateGlobalObject(*constructor), |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1001 | GlobalObject); |
| 1002 | } |
| 1003 | |
| 1004 | |
| 1005 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1006 | Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1007 | CALL_HEAP_FUNCTION( |
| 1008 | isolate(), |
| 1009 | isolate()->heap()->AllocateJSObjectFromMap(*map, NOT_TENURED), |
| 1010 | JSObject); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1014 | Handle<JSArray> Factory::NewJSArray(int capacity, |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1015 | ElementsKind elements_kind, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1016 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1017 | CALL_HEAP_FUNCTION(isolate(), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1018 | isolate()->heap()->AllocateJSArrayAndStorage( |
| 1019 | elements_kind, |
| 1020 | 0, |
| 1021 | capacity, |
| 1022 | INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, |
| 1023 | pretenure), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1024 | JSArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1028 | Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements, |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1029 | ElementsKind elements_kind, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1030 | PretenureFlag pretenure) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1031 | CALL_HEAP_FUNCTION( |
| 1032 | isolate(), |
| 1033 | isolate()->heap()->AllocateJSArrayWithElements(*elements, |
| 1034 | elements_kind, |
| 1035 | pretenure), |
| 1036 | JSArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1040 | void Factory::SetElementsCapacityAndLength(Handle<JSArray> array, |
| 1041 | int capacity, |
| 1042 | int length) { |
| 1043 | ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 1044 | CALL_HEAP_FUNCTION_VOID( |
| 1045 | isolate(), |
| 1046 | accessor->SetCapacityAndLength(*array, capacity, length)); |
| 1047 | } |
| 1048 | |
| 1049 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1050 | void Factory::SetContent(Handle<JSArray> array, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1051 | Handle<FixedArrayBase> elements) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1052 | CALL_HEAP_FUNCTION_VOID( |
| 1053 | isolate(), |
| 1054 | array->SetContent(*elements)); |
| 1055 | } |
| 1056 | |
| 1057 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1058 | void Factory::EnsureCanContainHeapObjectElements(Handle<JSArray> array) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1059 | CALL_HEAP_FUNCTION_VOID( |
| 1060 | isolate(), |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1061 | array->EnsureCanContainHeapObjectElements()); |
| 1062 | } |
| 1063 | |
| 1064 | |
| 1065 | void Factory::EnsureCanContainElements(Handle<JSArray> array, |
| 1066 | Handle<FixedArrayBase> elements, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1067 | uint32_t length, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1068 | EnsureElementsMode mode) { |
| 1069 | CALL_HEAP_FUNCTION_VOID( |
| 1070 | isolate(), |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1071 | array->EnsureCanContainElements(*elements, length, mode)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1075 | Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, |
| 1076 | Handle<Object> prototype) { |
| 1077 | CALL_HEAP_FUNCTION( |
| 1078 | isolate(), |
| 1079 | isolate()->heap()->AllocateJSProxy(*handler, *prototype), |
| 1080 | JSProxy); |
| 1081 | } |
| 1082 | |
| 1083 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1084 | void Factory::BecomeJSObject(Handle<JSReceiver> object) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1085 | CALL_HEAP_FUNCTION_VOID( |
| 1086 | isolate(), |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1087 | isolate()->heap()->ReinitializeJSReceiver( |
| 1088 | *object, JS_OBJECT_TYPE, JSObject::kHeaderSize)); |
| 1089 | } |
| 1090 | |
| 1091 | |
| 1092 | void Factory::BecomeJSFunction(Handle<JSReceiver> object) { |
| 1093 | CALL_HEAP_FUNCTION_VOID( |
| 1094 | isolate(), |
| 1095 | isolate()->heap()->ReinitializeJSReceiver( |
| 1096 | *object, JS_FUNCTION_TYPE, JSFunction::kSize)); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1100 | void Factory::SetIdentityHash(Handle<JSObject> object, Object* hash) { |
| 1101 | CALL_HEAP_FUNCTION_VOID( |
| 1102 | isolate(), |
| 1103 | object->SetIdentityHash(hash, ALLOW_CREATION)); |
| 1104 | } |
| 1105 | |
| 1106 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1107 | Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1108 | Handle<String> name, |
| 1109 | int number_of_literals, |
| 1110 | Handle<Code> code, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1111 | Handle<ScopeInfo> scope_info) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1112 | Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name); |
| 1113 | shared->set_code(*code); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1114 | shared->set_scope_info(*scope_info); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1115 | int literals_array_size = number_of_literals; |
| 1116 | // If the function contains object, regexp or array literals, |
| 1117 | // allocate extra space for a literals array prefix containing the |
| 1118 | // context. |
| 1119 | if (number_of_literals > 0) { |
| 1120 | literals_array_size += JSFunction::kLiteralsPrefixSize; |
| 1121 | } |
| 1122 | shared->set_num_literals(literals_array_size); |
| 1123 | return shared; |
| 1124 | } |
| 1125 | |
| 1126 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1127 | Handle<JSMessageObject> Factory::NewJSMessageObject( |
| 1128 | Handle<String> type, |
| 1129 | Handle<JSArray> arguments, |
| 1130 | int start_position, |
| 1131 | int end_position, |
| 1132 | Handle<Object> script, |
| 1133 | Handle<Object> stack_trace, |
| 1134 | Handle<Object> stack_frames) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1135 | CALL_HEAP_FUNCTION(isolate(), |
| 1136 | isolate()->heap()->AllocateJSMessageObject(*type, |
| 1137 | *arguments, |
| 1138 | start_position, |
| 1139 | end_position, |
| 1140 | *script, |
| 1141 | *stack_trace, |
| 1142 | *stack_frames), |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1143 | JSMessageObject); |
| 1144 | } |
| 1145 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1146 | Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(Handle<String> name) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1147 | CALL_HEAP_FUNCTION(isolate(), |
| 1148 | isolate()->heap()->AllocateSharedFunctionInfo(*name), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1149 | SharedFunctionInfo); |
| 1150 | } |
| 1151 | |
| 1152 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1153 | Handle<String> Factory::NumberToString(Handle<Object> number) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1154 | CALL_HEAP_FUNCTION(isolate(), |
| 1155 | isolate()->heap()->NumberToString(*number), String); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1159 | Handle<String> Factory::Uint32ToString(uint32_t value) { |
| 1160 | CALL_HEAP_FUNCTION(isolate(), |
| 1161 | isolate()->heap()->Uint32ToString(value), String); |
| 1162 | } |
| 1163 | |
| 1164 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1165 | Handle<SeededNumberDictionary> Factory::DictionaryAtNumberPut( |
| 1166 | Handle<SeededNumberDictionary> dictionary, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1167 | uint32_t key, |
| 1168 | Handle<Object> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1169 | CALL_HEAP_FUNCTION(isolate(), |
| 1170 | dictionary->AtNumberPut(key, *value), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1171 | SeededNumberDictionary); |
| 1172 | } |
| 1173 | |
| 1174 | |
| 1175 | Handle<UnseededNumberDictionary> Factory::DictionaryAtNumberPut( |
| 1176 | Handle<UnseededNumberDictionary> dictionary, |
| 1177 | uint32_t key, |
| 1178 | Handle<Object> value) { |
| 1179 | CALL_HEAP_FUNCTION(isolate(), |
| 1180 | dictionary->AtNumberPut(key, *value), |
| 1181 | UnseededNumberDictionary); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | |
| 1185 | Handle<JSFunction> Factory::NewFunctionHelper(Handle<String> name, |
| 1186 | Handle<Object> prototype) { |
| 1187 | Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1188 | CALL_HEAP_FUNCTION( |
| 1189 | isolate(), |
| 1190 | isolate()->heap()->AllocateFunction(*isolate()->function_map(), |
| 1191 | *function_share, |
| 1192 | *prototype), |
| 1193 | JSFunction); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | |
| 1197 | Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
| 1198 | Handle<Object> prototype) { |
| 1199 | Handle<JSFunction> fun = NewFunctionHelper(name, prototype); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1200 | fun->set_context(isolate()->context()->global_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1201 | return fun; |
| 1202 | } |
| 1203 | |
| 1204 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1205 | Handle<JSFunction> Factory::NewFunctionWithoutPrototypeHelper( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1206 | Handle<String> name, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1207 | LanguageMode language_mode) { |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1208 | Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1209 | Handle<Map> map = (language_mode == CLASSIC_MODE) |
| 1210 | ? isolate()->function_without_prototype_map() |
| 1211 | : isolate()->strict_mode_function_without_prototype_map(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1212 | CALL_HEAP_FUNCTION(isolate(), |
| 1213 | isolate()->heap()->AllocateFunction( |
| 1214 | *map, |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1215 | *function_share, |
| 1216 | *the_hole_value()), |
| 1217 | JSFunction); |
| 1218 | } |
| 1219 | |
| 1220 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1221 | Handle<JSFunction> Factory::NewFunctionWithoutPrototype( |
| 1222 | Handle<String> name, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1223 | LanguageMode language_mode) { |
| 1224 | Handle<JSFunction> fun = |
| 1225 | NewFunctionWithoutPrototypeHelper(name, language_mode); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1226 | fun->set_context(isolate()->context()->global_context()); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1227 | return fun; |
| 1228 | } |
| 1229 | |
| 1230 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1231 | Handle<Object> Factory::ToObject(Handle<Object> object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1232 | CALL_HEAP_FUNCTION(isolate(), object->ToObject(), Object); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1236 | Handle<Object> Factory::ToObject(Handle<Object> object, |
| 1237 | Handle<Context> global_context) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1238 | CALL_HEAP_FUNCTION(isolate(), object->ToObject(*global_context), Object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1242 | #ifdef ENABLE_DEBUGGER_SUPPORT |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1243 | Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) { |
| 1244 | // Get the original code of the function. |
| 1245 | Handle<Code> code(shared->code()); |
| 1246 | |
| 1247 | // Create a copy of the code before allocating the debug info object to avoid |
| 1248 | // allocation while setting up the debug info object. |
| 1249 | Handle<Code> original_code(*Factory::CopyCode(code)); |
| 1250 | |
| 1251 | // Allocate initial fixed array for active break points before allocating the |
| 1252 | // debug info object to avoid allocation while setting up the debug info |
| 1253 | // object. |
| 1254 | Handle<FixedArray> break_points( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1255 | NewFixedArray(Debug::kEstimatedNofBreakPointsInFunction)); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1256 | |
| 1257 | // Create and set up the debug info object. Debug info contains function, a |
| 1258 | // copy of the original code, the executing code and initial fixed array for |
| 1259 | // active break points. |
| 1260 | Handle<DebugInfo> debug_info = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1261 | Handle<DebugInfo>::cast(NewStruct(DEBUG_INFO_TYPE)); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1262 | debug_info->set_shared(*shared); |
| 1263 | debug_info->set_original_code(*original_code); |
| 1264 | debug_info->set_code(*code); |
| 1265 | debug_info->set_break_points(*break_points); |
| 1266 | |
| 1267 | // Link debug info to function. |
| 1268 | shared->set_debug_info(*debug_info); |
| 1269 | |
| 1270 | return debug_info; |
| 1271 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1272 | #endif |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1273 | |
| 1274 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1275 | Handle<JSObject> Factory::NewArgumentsObject(Handle<Object> callee, |
| 1276 | int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1277 | CALL_HEAP_FUNCTION( |
| 1278 | isolate(), |
| 1279 | isolate()->heap()->AllocateArgumentsObject(*callee, length), JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | |
| 1283 | Handle<JSFunction> Factory::CreateApiFunction( |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1284 | Handle<FunctionTemplateInfo> obj, ApiInstanceType instance_type) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1285 | Handle<Code> code = isolate()->builtins()->HandleApiCall(); |
| 1286 | Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1287 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1288 | int internal_field_count = 0; |
| 1289 | if (!obj->instance_template()->IsUndefined()) { |
| 1290 | Handle<ObjectTemplateInfo> instance_template = |
| 1291 | Handle<ObjectTemplateInfo>( |
| 1292 | ObjectTemplateInfo::cast(obj->instance_template())); |
| 1293 | internal_field_count = |
| 1294 | Smi::cast(instance_template->internal_field_count())->value(); |
| 1295 | } |
| 1296 | |
| 1297 | int instance_size = kPointerSize * internal_field_count; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1298 | InstanceType type = INVALID_TYPE; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1299 | switch (instance_type) { |
| 1300 | case JavaScriptObject: |
| 1301 | type = JS_OBJECT_TYPE; |
| 1302 | instance_size += JSObject::kHeaderSize; |
| 1303 | break; |
| 1304 | case InnerGlobalObject: |
| 1305 | type = JS_GLOBAL_OBJECT_TYPE; |
| 1306 | instance_size += JSGlobalObject::kSize; |
| 1307 | break; |
| 1308 | case OuterGlobalObject: |
| 1309 | type = JS_GLOBAL_PROXY_TYPE; |
| 1310 | instance_size += JSGlobalProxy::kSize; |
| 1311 | break; |
| 1312 | default: |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1313 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1314 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1315 | ASSERT(type != INVALID_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1316 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1317 | Handle<JSFunction> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1318 | NewFunction(Factory::empty_symbol(), |
| 1319 | type, |
| 1320 | instance_size, |
| 1321 | code, |
| 1322 | true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1323 | // Set class name. |
| 1324 | Handle<Object> class_name = Handle<Object>(obj->class_name()); |
| 1325 | if (class_name->IsString()) { |
| 1326 | result->shared()->set_instance_class_name(*class_name); |
| 1327 | result->shared()->set_name(*class_name); |
| 1328 | } |
| 1329 | |
| 1330 | Handle<Map> map = Handle<Map>(result->initial_map()); |
| 1331 | |
| 1332 | // Mark as undetectable if needed. |
| 1333 | if (obj->undetectable()) { |
| 1334 | map->set_is_undetectable(); |
| 1335 | } |
| 1336 | |
| 1337 | // Mark as hidden for the __proto__ accessor if needed. |
| 1338 | if (obj->hidden_prototype()) { |
| 1339 | map->set_is_hidden_prototype(); |
| 1340 | } |
| 1341 | |
| 1342 | // Mark as needs_access_check if needed. |
| 1343 | if (obj->needs_access_check()) { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1344 | map->set_is_access_check_needed(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1347 | // Set interceptor information in the map. |
| 1348 | if (!obj->named_property_handler()->IsUndefined()) { |
| 1349 | map->set_has_named_interceptor(); |
| 1350 | } |
| 1351 | if (!obj->indexed_property_handler()->IsUndefined()) { |
| 1352 | map->set_has_indexed_interceptor(); |
| 1353 | } |
| 1354 | |
| 1355 | // Set instance call-as-function information in the map. |
| 1356 | if (!obj->instance_call_handler()->IsUndefined()) { |
| 1357 | map->set_has_instance_call_handler(); |
| 1358 | } |
| 1359 | |
| 1360 | result->shared()->set_function_data(*obj); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1361 | result->shared()->set_construct_stub(*construct_stub); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1362 | result->shared()->DontAdaptArguments(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1363 | |
| 1364 | // Recursively copy parent templates' accessors, 'data' may be modified. |
| 1365 | Handle<DescriptorArray> array = |
| 1366 | Handle<DescriptorArray>(map->instance_descriptors()); |
| 1367 | while (true) { |
| 1368 | Handle<Object> props = Handle<Object>(obj->property_accessors()); |
| 1369 | if (!props->IsUndefined()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1370 | array = CopyAppendCallbackDescriptors(array, props); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1371 | } |
| 1372 | Handle<Object> parent = Handle<Object>(obj->parent_template()); |
| 1373 | if (parent->IsUndefined()) break; |
| 1374 | obj = Handle<FunctionTemplateInfo>::cast(parent); |
| 1375 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1376 | if (!array->IsEmpty()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1377 | map->set_instance_descriptors(*array); |
| 1378 | } |
| 1379 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1380 | ASSERT(result->shared()->IsApiFunction()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1381 | return result; |
| 1382 | } |
| 1383 | |
| 1384 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1385 | Handle<MapCache> Factory::NewMapCache(int at_least_space_for) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1386 | CALL_HEAP_FUNCTION(isolate(), |
| 1387 | MapCache::Allocate(at_least_space_for), MapCache); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1391 | MUST_USE_RESULT static MaybeObject* UpdateMapCacheWith(Context* context, |
| 1392 | FixedArray* keys, |
| 1393 | Map* map) { |
| 1394 | Object* result; |
| 1395 | { MaybeObject* maybe_result = |
| 1396 | MapCache::cast(context->map_cache())->Put(keys, map); |
| 1397 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1398 | } |
| 1399 | context->set_map_cache(MapCache::cast(result)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1400 | return result; |
| 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | Handle<MapCache> Factory::AddToMapCache(Handle<Context> context, |
| 1405 | Handle<FixedArray> keys, |
| 1406 | Handle<Map> map) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1407 | CALL_HEAP_FUNCTION(isolate(), |
| 1408 | UpdateMapCacheWith(*context, *keys, *map), MapCache); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | |
| 1412 | Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, |
| 1413 | Handle<FixedArray> keys) { |
| 1414 | if (context->map_cache()->IsUndefined()) { |
| 1415 | // Allocate the new map cache for the global context. |
| 1416 | Handle<MapCache> new_cache = NewMapCache(24); |
| 1417 | context->set_map_cache(*new_cache); |
| 1418 | } |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1419 | // Check to see whether there is a matching element in the cache. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1420 | Handle<MapCache> cache = |
| 1421 | Handle<MapCache>(MapCache::cast(context->map_cache())); |
| 1422 | Handle<Object> result = Handle<Object>(cache->Lookup(*keys)); |
| 1423 | if (result->IsMap()) return Handle<Map>::cast(result); |
| 1424 | // Create a new map and add it to the cache. |
| 1425 | Handle<Map> map = |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1426 | CopyMap(Handle<Map>(context->object_function()->initial_map()), |
| 1427 | keys->length()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1428 | AddToMapCache(context, keys, map); |
| 1429 | return Handle<Map>(map); |
| 1430 | } |
| 1431 | |
| 1432 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1433 | void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, |
| 1434 | JSRegExp::Type type, |
| 1435 | Handle<String> source, |
| 1436 | JSRegExp::Flags flags, |
| 1437 | Handle<Object> data) { |
| 1438 | Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize); |
| 1439 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1440 | store->set(JSRegExp::kTagIndex, Smi::FromInt(type)); |
| 1441 | store->set(JSRegExp::kSourceIndex, *source); |
| 1442 | store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value())); |
| 1443 | store->set(JSRegExp::kAtomPatternIndex, *data); |
| 1444 | regexp->set_data(*store); |
| 1445 | } |
| 1446 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1447 | void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp, |
| 1448 | JSRegExp::Type type, |
| 1449 | Handle<String> source, |
| 1450 | JSRegExp::Flags flags, |
| 1451 | int capture_count) { |
| 1452 | Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1453 | Smi* uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1454 | store->set(JSRegExp::kTagIndex, Smi::FromInt(type)); |
| 1455 | store->set(JSRegExp::kSourceIndex, *source); |
| 1456 | store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value())); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1457 | store->set(JSRegExp::kIrregexpASCIICodeIndex, uninitialized); |
| 1458 | store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized); |
| 1459 | store->set(JSRegExp::kIrregexpASCIICodeSavedIndex, uninitialized); |
| 1460 | store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1461 | store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0)); |
| 1462 | store->set(JSRegExp::kIrregexpCaptureCountIndex, |
| 1463 | Smi::FromInt(capture_count)); |
| 1464 | regexp->set_data(*store); |
| 1465 | } |
| 1466 | |
| 1467 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1468 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1469 | void Factory::ConfigureInstance(Handle<FunctionTemplateInfo> desc, |
| 1470 | Handle<JSObject> instance, |
| 1471 | bool* pending_exception) { |
| 1472 | // Configure the instance by adding the properties specified by the |
| 1473 | // instance template. |
| 1474 | Handle<Object> instance_template = Handle<Object>(desc->instance_template()); |
| 1475 | if (!instance_template->IsUndefined()) { |
| 1476 | Execution::ConfigureInstance(instance, |
| 1477 | instance_template, |
| 1478 | pending_exception); |
| 1479 | } else { |
| 1480 | *pending_exception = false; |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1485 | Handle<Object> Factory::GlobalConstantFor(Handle<String> name) { |
| 1486 | Heap* h = isolate()->heap(); |
| 1487 | if (name->Equals(h->undefined_symbol())) return undefined_value(); |
| 1488 | if (name->Equals(h->nan_symbol())) return nan_value(); |
| 1489 | if (name->Equals(h->infinity_symbol())) return infinity_value(); |
| 1490 | return Handle<Object>::null(); |
| 1491 | } |
| 1492 | |
| 1493 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1494 | Handle<Object> Factory::ToBoolean(bool value) { |
| 1495 | return Handle<Object>(value |
| 1496 | ? isolate()->heap()->true_value() |
| 1497 | : isolate()->heap()->false_value()); |
| 1498 | } |
| 1499 | |
| 1500 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1501 | } } // namespace v8::internal |