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