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