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