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