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