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