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