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