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