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