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