danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "api.h" |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 31 | #include "debug.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "execution.h" |
| 33 | #include "factory.h" |
| 34 | #include "macro-assembler.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 35 | #include "objects.h" |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 36 | #include "objects-visiting.h" |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 37 | #include "platform.h" |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 38 | #include "scopeinfo.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 40 | namespace v8 { |
| 41 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
| 43 | |
| 44 | Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) { |
| 45 | ASSERT(0 <= size); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 46 | CALL_HEAP_FUNCTION( |
| 47 | isolate(), |
| 48 | isolate()->heap()->AllocateFixedArray(size, pretenure), |
| 49 | FixedArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 53 | Handle<FixedArray> Factory::NewFixedArrayWithHoles(int size, |
| 54 | PretenureFlag pretenure) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 55 | ASSERT(0 <= size); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 56 | CALL_HEAP_FUNCTION( |
| 57 | isolate(), |
| 58 | isolate()->heap()->AllocateFixedArrayWithHoles(size, pretenure), |
| 59 | FixedArray); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 63 | Handle<FixedDoubleArray> Factory::NewFixedDoubleArray(int size, |
| 64 | PretenureFlag pretenure) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 65 | ASSERT(0 <= size); |
| 66 | CALL_HEAP_FUNCTION( |
| 67 | isolate(), |
| 68 | isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 69 | FixedDoubleArray); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 73 | Handle<StringDictionary> Factory::NewStringDictionary(int at_least_space_for) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 74 | ASSERT(0 <= at_least_space_for); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 75 | CALL_HEAP_FUNCTION(isolate(), |
| 76 | StringDictionary::Allocate(at_least_space_for), |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 77 | StringDictionary); |
| 78 | } |
| 79 | |
| 80 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 81 | Handle<SeededNumberDictionary> Factory::NewSeededNumberDictionary( |
| 82 | int at_least_space_for) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 83 | ASSERT(0 <= at_least_space_for); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 84 | CALL_HEAP_FUNCTION(isolate(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 85 | SeededNumberDictionary::Allocate(at_least_space_for), |
| 86 | SeededNumberDictionary); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | Handle<UnseededNumberDictionary> Factory::NewUnseededNumberDictionary( |
| 91 | int at_least_space_for) { |
| 92 | ASSERT(0 <= at_least_space_for); |
| 93 | CALL_HEAP_FUNCTION(isolate(), |
| 94 | UnseededNumberDictionary::Allocate(at_least_space_for), |
| 95 | UnseededNumberDictionary); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 99 | Handle<ObjectHashSet> Factory::NewObjectHashSet(int at_least_space_for) { |
| 100 | ASSERT(0 <= at_least_space_for); |
| 101 | CALL_HEAP_FUNCTION(isolate(), |
| 102 | ObjectHashSet::Allocate(at_least_space_for), |
| 103 | ObjectHashSet); |
| 104 | } |
| 105 | |
| 106 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 107 | Handle<ObjectHashTable> Factory::NewObjectHashTable(int at_least_space_for) { |
| 108 | ASSERT(0 <= at_least_space_for); |
| 109 | CALL_HEAP_FUNCTION(isolate(), |
| 110 | ObjectHashTable::Allocate(at_least_space_for), |
| 111 | ObjectHashTable); |
| 112 | } |
| 113 | |
| 114 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 115 | Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors, |
| 116 | int slack) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 117 | ASSERT(0 <= number_of_descriptors); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 118 | CALL_HEAP_FUNCTION(isolate(), |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 119 | DescriptorArray::Allocate(number_of_descriptors, slack), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 120 | DescriptorArray); |
| 121 | } |
| 122 | |
| 123 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 124 | Handle<DeoptimizationInputData> Factory::NewDeoptimizationInputData( |
| 125 | int deopt_entry_count, |
| 126 | PretenureFlag pretenure) { |
| 127 | ASSERT(deopt_entry_count > 0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 128 | CALL_HEAP_FUNCTION(isolate(), |
| 129 | DeoptimizationInputData::Allocate(deopt_entry_count, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 130 | pretenure), |
| 131 | DeoptimizationInputData); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | Handle<DeoptimizationOutputData> Factory::NewDeoptimizationOutputData( |
| 136 | int deopt_entry_count, |
| 137 | PretenureFlag pretenure) { |
| 138 | ASSERT(deopt_entry_count > 0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 139 | CALL_HEAP_FUNCTION(isolate(), |
| 140 | DeoptimizationOutputData::Allocate(deopt_entry_count, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 141 | pretenure), |
| 142 | DeoptimizationOutputData); |
| 143 | } |
| 144 | |
| 145 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 146 | Handle<AccessorPair> Factory::NewAccessorPair() { |
| 147 | CALL_HEAP_FUNCTION(isolate(), |
| 148 | isolate()->heap()->AllocateAccessorPair(), |
| 149 | AccessorPair); |
| 150 | } |
| 151 | |
| 152 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 153 | Handle<TypeFeedbackInfo> Factory::NewTypeFeedbackInfo() { |
| 154 | CALL_HEAP_FUNCTION(isolate(), |
| 155 | isolate()->heap()->AllocateTypeFeedbackInfo(), |
| 156 | TypeFeedbackInfo); |
| 157 | } |
| 158 | |
| 159 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 160 | // Internalized strings are created in the old generation (data space). |
| 161 | Handle<String> Factory::InternalizeUtf8String(Vector<const char> string) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 162 | CALL_HEAP_FUNCTION(isolate(), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 163 | isolate()->heap()->InternalizeUtf8String(string), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 164 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 165 | } |
| 166 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 167 | // Internalized strings are created in the old generation (data space). |
| 168 | Handle<String> Factory::InternalizeString(Handle<String> string) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 169 | CALL_HEAP_FUNCTION(isolate(), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 170 | isolate()->heap()->InternalizeString(*string), |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 171 | String); |
| 172 | } |
| 173 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 174 | Handle<String> Factory::InternalizeOneByteString(Vector<const uint8_t> string) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 175 | CALL_HEAP_FUNCTION(isolate(), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 176 | isolate()->heap()->InternalizeOneByteString(string), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 177 | String); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 178 | } |
| 179 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 180 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 181 | Handle<String> Factory::InternalizeOneByteString( |
| 182 | Handle<SeqOneByteString> string, int from, int length) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 183 | CALL_HEAP_FUNCTION(isolate(), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 184 | isolate()->heap()->InternalizeOneByteString( |
| 185 | string, from, length), |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 186 | String); |
| 187 | } |
| 188 | |
| 189 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 190 | Handle<String> Factory::InternalizeTwoByteString(Vector<const uc16> string) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 191 | CALL_HEAP_FUNCTION(isolate(), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 192 | isolate()->heap()->InternalizeTwoByteString(string), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 193 | String); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 194 | } |
| 195 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 196 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 197 | Handle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string, |
| 198 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 199 | CALL_HEAP_FUNCTION( |
| 200 | isolate(), |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 201 | isolate()->heap()->AllocateStringFromOneByte(string, pretenure), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 202 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | Handle<String> Factory::NewStringFromUtf8(Vector<const char> string, |
| 206 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 207 | CALL_HEAP_FUNCTION( |
| 208 | isolate(), |
| 209 | isolate()->heap()->AllocateStringFromUtf8(string, pretenure), |
| 210 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 214 | Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string, |
| 215 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 216 | CALL_HEAP_FUNCTION( |
| 217 | isolate(), |
| 218 | isolate()->heap()->AllocateStringFromTwoByte(string, pretenure), |
| 219 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 223 | Handle<SeqOneByteString> Factory::NewRawOneByteString(int length, |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 224 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 225 | CALL_HEAP_FUNCTION( |
| 226 | isolate(), |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 227 | isolate()->heap()->AllocateRawOneByteString(length, pretenure), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 228 | SeqOneByteString); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 232 | Handle<SeqTwoByteString> Factory::NewRawTwoByteString(int length, |
| 233 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 234 | CALL_HEAP_FUNCTION( |
| 235 | isolate(), |
| 236 | isolate()->heap()->AllocateRawTwoByteString(length, pretenure), |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 237 | SeqTwoByteString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | |
| 241 | Handle<String> Factory::NewConsString(Handle<String> first, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 242 | Handle<String> second) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 243 | CALL_HEAP_FUNCTION(isolate(), |
| 244 | isolate()->heap()->AllocateConsString(*first, *second), |
| 245 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 249 | Handle<String> Factory::NewSubString(Handle<String> str, |
| 250 | int begin, |
| 251 | int end) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 252 | CALL_HEAP_FUNCTION(isolate(), |
| 253 | str->SubString(begin, end), |
| 254 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +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 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 268 | Handle<String> Factory::NewExternalStringFromAscii( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 269 | const ExternalAsciiString::Resource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 270 | CALL_HEAP_FUNCTION( |
| 271 | isolate(), |
| 272 | isolate()->heap()->AllocateExternalStringFromAscii(resource), |
| 273 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | |
| 277 | Handle<String> Factory::NewExternalStringFromTwoByte( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 278 | const ExternalTwoByteString::Resource* resource) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 279 | CALL_HEAP_FUNCTION( |
| 280 | isolate(), |
| 281 | isolate()->heap()->AllocateExternalStringFromTwoByte(resource), |
| 282 | String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 286 | Handle<Symbol> Factory::NewSymbol() { |
| 287 | CALL_HEAP_FUNCTION( |
| 288 | isolate(), |
| 289 | isolate()->heap()->AllocateSymbol(), |
| 290 | Symbol); |
| 291 | } |
| 292 | |
| 293 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 294 | Handle<Context> Factory::NewNativeContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 295 | CALL_HEAP_FUNCTION( |
| 296 | isolate(), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 297 | isolate()->heap()->AllocateNativeContext(), |
| 298 | Context); |
| 299 | } |
| 300 | |
| 301 | |
| 302 | Handle<Context> Factory::NewGlobalContext(Handle<JSFunction> function, |
| 303 | Handle<ScopeInfo> scope_info) { |
| 304 | CALL_HEAP_FUNCTION( |
| 305 | isolate(), |
| 306 | isolate()->heap()->AllocateGlobalContext(*function, *scope_info), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 307 | Context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 311 | Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 312 | CALL_HEAP_FUNCTION( |
| 313 | isolate(), |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 314 | isolate()->heap()->AllocateModuleContext(*scope_info), |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 315 | Context); |
| 316 | } |
| 317 | |
| 318 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 319 | Handle<Context> Factory::NewFunctionContext(int length, |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 320 | Handle<JSFunction> function) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 321 | CALL_HEAP_FUNCTION( |
| 322 | isolate(), |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 323 | isolate()->heap()->AllocateFunctionContext(length, *function), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 324 | Context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 328 | Handle<Context> Factory::NewCatchContext(Handle<JSFunction> function, |
| 329 | Handle<Context> previous, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 330 | Handle<String> name, |
| 331 | Handle<Object> thrown_object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 332 | CALL_HEAP_FUNCTION( |
| 333 | isolate(), |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 334 | isolate()->heap()->AllocateCatchContext(*function, |
| 335 | *previous, |
| 336 | *name, |
| 337 | *thrown_object), |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 338 | Context); |
| 339 | } |
| 340 | |
| 341 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 342 | Handle<Context> Factory::NewWithContext(Handle<JSFunction> function, |
| 343 | Handle<Context> previous, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 344 | Handle<JSObject> extension) { |
| 345 | CALL_HEAP_FUNCTION( |
| 346 | isolate(), |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 347 | isolate()->heap()->AllocateWithContext(*function, *previous, *extension), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 348 | Context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 352 | Handle<Context> Factory::NewBlockContext(Handle<JSFunction> function, |
| 353 | Handle<Context> previous, |
| 354 | Handle<ScopeInfo> scope_info) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 355 | CALL_HEAP_FUNCTION( |
| 356 | isolate(), |
| 357 | isolate()->heap()->AllocateBlockContext(*function, |
| 358 | *previous, |
| 359 | *scope_info), |
| 360 | Context); |
| 361 | } |
| 362 | |
| 363 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 364 | Handle<Struct> Factory::NewStruct(InstanceType type) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 365 | CALL_HEAP_FUNCTION( |
| 366 | isolate(), |
| 367 | isolate()->heap()->AllocateStruct(type), |
| 368 | Struct); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 372 | Handle<DeclaredAccessorInfo> Factory::NewDeclaredAccessorInfo() { |
| 373 | Handle<DeclaredAccessorInfo> info = |
| 374 | Handle<DeclaredAccessorInfo>::cast( |
| 375 | NewStruct(DECLARED_ACCESSOR_INFO_TYPE)); |
| 376 | info->set_flag(0); // Must clear the flag, it was initialized as undefined. |
| 377 | return info; |
| 378 | } |
| 379 | |
| 380 | |
| 381 | Handle<ExecutableAccessorInfo> Factory::NewExecutableAccessorInfo() { |
| 382 | Handle<ExecutableAccessorInfo> info = |
| 383 | Handle<ExecutableAccessorInfo>::cast( |
| 384 | NewStruct(EXECUTABLE_ACCESSOR_INFO_TYPE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 385 | info->set_flag(0); // Must clear the flag, it was initialized as undefined. |
| 386 | return info; |
| 387 | } |
| 388 | |
| 389 | |
| 390 | Handle<Script> Factory::NewScript(Handle<String> source) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 391 | // Generate id for this script. |
| 392 | int id; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 393 | Heap* heap = isolate()->heap(); |
| 394 | if (heap->last_script_id()->IsUndefined()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 395 | // Script ids start from one. |
| 396 | id = 1; |
| 397 | } else { |
| 398 | // Increment id, wrap when positive smi is exhausted. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 399 | id = Smi::cast(heap->last_script_id())->value(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 400 | id++; |
| 401 | if (!Smi::IsValid(id)) { |
| 402 | id = 0; |
| 403 | } |
| 404 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 405 | heap->SetLastScriptId(Smi::FromInt(id)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 406 | |
| 407 | // Create and initialize script object. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 408 | Handle<Foreign> wrapper = NewForeign(0, TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 409 | Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE)); |
| 410 | script->set_source(*source); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 411 | script->set_name(heap->undefined_value()); |
| 412 | script->set_id(heap->last_script_id()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 413 | script->set_line_offset(Smi::FromInt(0)); |
| 414 | script->set_column_offset(Smi::FromInt(0)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 415 | script->set_data(heap->undefined_value()); |
| 416 | script->set_context_data(heap->undefined_value()); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 417 | script->set_type(Smi::FromInt(Script::TYPE_NORMAL)); |
| 418 | script->set_compilation_type(Smi::FromInt(Script::COMPILATION_TYPE_HOST)); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 419 | script->set_compilation_state( |
| 420 | Smi::FromInt(Script::COMPILATION_STATE_INITIAL)); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 421 | script->set_wrapper(*wrapper); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 422 | script->set_line_ends(heap->undefined_value()); |
| 423 | script->set_eval_from_shared(heap->undefined_value()); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 424 | script->set_eval_from_instructions_offset(Smi::FromInt(0)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 425 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 426 | return script; |
| 427 | } |
| 428 | |
| 429 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 430 | Handle<Foreign> Factory::NewForeign(Address addr, PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 431 | CALL_HEAP_FUNCTION(isolate(), |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 432 | isolate()->heap()->AllocateForeign(addr, pretenure), |
| 433 | Foreign); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 437 | Handle<Foreign> Factory::NewForeign(const AccessorDescriptor* desc) { |
| 438 | return NewForeign((Address) desc, TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 442 | Handle<ByteArray> Factory::NewByteArray(int length, PretenureFlag pretenure) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 443 | ASSERT(0 <= length); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 444 | CALL_HEAP_FUNCTION( |
| 445 | isolate(), |
| 446 | isolate()->heap()->AllocateByteArray(length, pretenure), |
| 447 | ByteArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 451 | Handle<ExternalArray> Factory::NewExternalArray(int length, |
| 452 | ExternalArrayType array_type, |
| 453 | void* external_pointer, |
| 454 | PretenureFlag pretenure) { |
| 455 | ASSERT(0 <= length); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 456 | CALL_HEAP_FUNCTION( |
| 457 | isolate(), |
| 458 | isolate()->heap()->AllocateExternalArray(length, |
| 459 | array_type, |
| 460 | external_pointer, |
| 461 | pretenure), |
| 462 | ExternalArray); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 466 | Handle<JSGlobalPropertyCell> Factory::NewJSGlobalPropertyCell( |
| 467 | Handle<Object> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 468 | CALL_HEAP_FUNCTION( |
| 469 | isolate(), |
| 470 | isolate()->heap()->AllocateJSGlobalPropertyCell(*value), |
| 471 | JSGlobalPropertyCell); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 475 | Handle<Map> Factory::NewMap(InstanceType type, |
| 476 | int instance_size, |
| 477 | ElementsKind elements_kind) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 478 | CALL_HEAP_FUNCTION( |
| 479 | isolate(), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 480 | isolate()->heap()->AllocateMap(type, instance_size, elements_kind), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 481 | Map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | |
| 485 | Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 486 | CALL_HEAP_FUNCTION( |
| 487 | isolate(), |
| 488 | isolate()->heap()->AllocateFunctionPrototype(*function), |
| 489 | JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 493 | Handle<Map> Factory::CopyWithPreallocatedFieldDescriptors(Handle<Map> src) { |
| 494 | CALL_HEAP_FUNCTION( |
| 495 | isolate(), src->CopyWithPreallocatedFieldDescriptors(), Map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 499 | Handle<Map> Factory::CopyMap(Handle<Map> src, |
| 500 | int extra_inobject_properties) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 501 | Handle<Map> copy = CopyWithPreallocatedFieldDescriptors(src); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 502 | // Check that we do not overflow the instance size when adding the |
| 503 | // extra inobject properties. |
| 504 | int instance_size_delta = extra_inobject_properties * kPointerSize; |
| 505 | int max_instance_size_delta = |
| 506 | JSObject::kMaxInstanceSize - copy->instance_size(); |
| 507 | if (instance_size_delta > max_instance_size_delta) { |
| 508 | // If the instance size overflows, we allocate as many properties |
| 509 | // as we can as inobject properties. |
| 510 | instance_size_delta = max_instance_size_delta; |
| 511 | extra_inobject_properties = max_instance_size_delta >> kPointerSizeLog2; |
| 512 | } |
| 513 | // Adjust the map with the extra inobject properties. |
| 514 | int inobject_properties = |
| 515 | copy->inobject_properties() + extra_inobject_properties; |
| 516 | copy->set_inobject_properties(inobject_properties); |
| 517 | copy->set_unused_property_fields(inobject_properties); |
| 518 | copy->set_instance_size(copy->instance_size() + instance_size_delta); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 519 | copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 520 | return copy; |
| 521 | } |
| 522 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 523 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 524 | Handle<Map> Factory::CopyMap(Handle<Map> src) { |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 525 | CALL_HEAP_FUNCTION(isolate(), src->Copy(), Map); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 529 | Handle<Map> Factory::GetElementsTransitionMap( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 530 | Handle<JSObject> src, |
| 531 | ElementsKind elements_kind) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 532 | Isolate* i = isolate(); |
| 533 | CALL_HEAP_FUNCTION(i, |
| 534 | src->GetElementsTransitionMap(i, elements_kind), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 535 | Map); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 539 | Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 540 | CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 544 | Handle<FixedArray> Factory::CopySizeFixedArray(Handle<FixedArray> array, |
| 545 | int new_length) { |
| 546 | CALL_HEAP_FUNCTION(isolate(), array->CopySize(new_length), FixedArray); |
| 547 | } |
| 548 | |
| 549 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 550 | Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray( |
| 551 | Handle<FixedDoubleArray> array) { |
| 552 | CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray); |
| 553 | } |
| 554 | |
| 555 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 556 | Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo( |
| 557 | Handle<SharedFunctionInfo> function_info, |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 558 | Handle<Map> function_map, |
| 559 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 560 | CALL_HEAP_FUNCTION( |
| 561 | isolate(), |
| 562 | isolate()->heap()->AllocateFunction(*function_map, |
| 563 | *function_info, |
| 564 | isolate()->heap()->the_hole_value(), |
| 565 | pretenure), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | JSFunction); |
| 567 | } |
| 568 | |
| 569 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 570 | Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
| 571 | Handle<SharedFunctionInfo> function_info, |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 572 | Handle<Context> context, |
| 573 | PretenureFlag pretenure) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 574 | Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 575 | function_info, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 576 | function_info->is_classic_mode() |
| 577 | ? isolate()->function_map() |
| 578 | : isolate()->strict_mode_function_map(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 579 | pretenure); |
| 580 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 581 | if (function_info->ic_age() != isolate()->heap()->global_ic_age()) { |
| 582 | function_info->ResetForNewContext(isolate()->heap()->global_ic_age()); |
| 583 | } |
| 584 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 585 | result->set_context(*context); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 586 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 587 | int index = function_info->SearchOptimizedCodeMap(context->native_context()); |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 588 | if (!function_info->bound() && index < 0) { |
| 589 | int number_of_literals = function_info->num_literals(); |
| 590 | Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure); |
| 591 | if (number_of_literals > 0) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 592 | // Store the native context in the literals array prefix. This |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 593 | // context will be used when creating object, regexp and array |
| 594 | // literals in this function. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 595 | literals->set(JSFunction::kLiteralNativeContextIndex, |
| 596 | context->native_context()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 597 | } |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 598 | result->set_literals(*literals); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 599 | } |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 600 | |
| 601 | if (index > 0) { |
| 602 | // Caching of optimized code enabled and optimized code found. |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 603 | function_info->InstallFromOptimizedCodeMap(*result, index); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 604 | return result; |
| 605 | } |
| 606 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 607 | if (V8::UseCrankshaft() && |
| 608 | FLAG_always_opt && |
| 609 | result->is_compiled() && |
| 610 | !function_info->is_toplevel() && |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 611 | function_info->allows_lazy_compilation() && |
| 612 | !function_info->optimization_disabled()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 613 | result->MarkForLazyRecompilation(); |
| 614 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 615 | return result; |
| 616 | } |
| 617 | |
| 618 | |
| 619 | Handle<Object> Factory::NewNumber(double value, |
| 620 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 621 | CALL_HEAP_FUNCTION( |
| 622 | isolate(), |
| 623 | isolate()->heap()->NumberFromDouble(value, pretenure), Object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 627 | Handle<Object> Factory::NewNumberFromInt(int32_t value, |
| 628 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 629 | CALL_HEAP_FUNCTION( |
| 630 | isolate(), |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 631 | isolate()->heap()->NumberFromInt32(value, pretenure), Object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 635 | Handle<Object> Factory::NewNumberFromUint(uint32_t value, |
| 636 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 637 | CALL_HEAP_FUNCTION( |
| 638 | isolate(), |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 639 | isolate()->heap()->NumberFromUint32(value, pretenure), Object); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 643 | Handle<JSObject> Factory::NewNeanderObject() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 644 | CALL_HEAP_FUNCTION( |
| 645 | isolate(), |
| 646 | isolate()->heap()->AllocateJSObjectFromMap( |
| 647 | isolate()->heap()->neander_map()), |
| 648 | JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | |
| 652 | Handle<Object> Factory::NewTypeError(const char* type, |
| 653 | Vector< Handle<Object> > args) { |
| 654 | return NewError("MakeTypeError", type, args); |
| 655 | } |
| 656 | |
| 657 | |
| 658 | Handle<Object> Factory::NewTypeError(Handle<String> message) { |
| 659 | return NewError("$TypeError", message); |
| 660 | } |
| 661 | |
| 662 | |
| 663 | Handle<Object> Factory::NewRangeError(const char* type, |
| 664 | Vector< Handle<Object> > args) { |
| 665 | return NewError("MakeRangeError", type, args); |
| 666 | } |
| 667 | |
| 668 | |
| 669 | Handle<Object> Factory::NewRangeError(Handle<String> message) { |
| 670 | return NewError("$RangeError", message); |
| 671 | } |
| 672 | |
| 673 | |
| 674 | Handle<Object> Factory::NewSyntaxError(const char* type, Handle<JSArray> args) { |
| 675 | return NewError("MakeSyntaxError", type, args); |
| 676 | } |
| 677 | |
| 678 | |
| 679 | Handle<Object> Factory::NewSyntaxError(Handle<String> message) { |
| 680 | return NewError("$SyntaxError", message); |
| 681 | } |
| 682 | |
| 683 | |
| 684 | Handle<Object> Factory::NewReferenceError(const char* type, |
| 685 | Vector< Handle<Object> > args) { |
| 686 | return NewError("MakeReferenceError", type, args); |
| 687 | } |
| 688 | |
| 689 | |
| 690 | Handle<Object> Factory::NewReferenceError(Handle<String> message) { |
| 691 | return NewError("$ReferenceError", message); |
| 692 | } |
| 693 | |
| 694 | |
| 695 | Handle<Object> Factory::NewError(const char* maker, const char* type, |
| 696 | Vector< Handle<Object> > args) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 697 | v8::HandleScope scope; // Instantiate a closeable HandleScope for EscapeFrom. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 698 | Handle<FixedArray> array = NewFixedArray(args.length()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 699 | for (int i = 0; i < args.length(); i++) { |
| 700 | array->set(i, *args[i]); |
| 701 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 702 | Handle<JSArray> object = NewJSArrayWithElements(array); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 703 | Handle<Object> result = NewError(maker, type, object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 704 | return result.EscapeFrom(&scope); |
| 705 | } |
| 706 | |
| 707 | |
| 708 | Handle<Object> Factory::NewEvalError(const char* type, |
| 709 | Vector< Handle<Object> > args) { |
| 710 | return NewError("MakeEvalError", type, args); |
| 711 | } |
| 712 | |
| 713 | |
| 714 | Handle<Object> Factory::NewError(const char* type, |
| 715 | Vector< Handle<Object> > args) { |
| 716 | return NewError("MakeError", type, args); |
| 717 | } |
| 718 | |
| 719 | |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 720 | Handle<String> Factory::EmergencyNewError(const char* type, |
| 721 | Handle<JSArray> args) { |
| 722 | const int kBufferSize = 1000; |
| 723 | char buffer[kBufferSize]; |
| 724 | size_t space = kBufferSize; |
| 725 | char* p = &buffer[0]; |
| 726 | |
| 727 | Vector<char> v(buffer, kBufferSize); |
| 728 | OS::StrNCpy(v, type, space); |
| 729 | space -= Min(space, strlen(type)); |
| 730 | p = &buffer[kBufferSize] - space; |
| 731 | |
| 732 | for (unsigned i = 0; i < ARRAY_SIZE(args); i++) { |
| 733 | if (space > 0) { |
| 734 | *p++ = ' '; |
| 735 | space--; |
| 736 | if (space > 0) { |
| 737 | MaybeObject* maybe_arg = args->GetElement(i); |
| 738 | Handle<String> arg_str(reinterpret_cast<String*>(maybe_arg)); |
| 739 | const char* arg = *arg_str->ToCString(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 740 | Vector<char> v2(p, static_cast<int>(space)); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 741 | OS::StrNCpy(v2, arg, space); |
| 742 | space -= Min(space, strlen(arg)); |
| 743 | p = &buffer[kBufferSize] - space; |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | if (space > 0) { |
| 748 | *p = '\0'; |
| 749 | } else { |
| 750 | buffer[kBufferSize - 1] = '\0'; |
| 751 | } |
| 752 | Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED); |
| 753 | return error_string; |
| 754 | } |
| 755 | |
| 756 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 757 | Handle<Object> Factory::NewError(const char* maker, |
| 758 | const char* type, |
| 759 | Handle<JSArray> args) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 760 | Handle<String> make_str = InternalizeUtf8String(maker); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 761 | Handle<Object> fun_obj( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 762 | isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str), |
| 763 | isolate()); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 764 | // If the builtins haven't been properly configured yet this error |
| 765 | // constructor may not have been defined. Bail out. |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 766 | if (!fun_obj->IsJSFunction()) { |
| 767 | return EmergencyNewError(type, args); |
| 768 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 769 | Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 770 | Handle<Object> type_obj = InternalizeUtf8String(type); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 771 | Handle<Object> argv[] = { type_obj, args }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 772 | |
| 773 | // Invoke the JavaScript factory method. If an exception is thrown while |
| 774 | // running the factory method, use the exception as the result. |
| 775 | bool caught_exception; |
| 776 | Handle<Object> result = Execution::TryCall(fun, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 777 | isolate()->js_builtins_object(), |
| 778 | ARRAY_SIZE(argv), |
| 779 | argv, |
| 780 | &caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 781 | return result; |
| 782 | } |
| 783 | |
| 784 | |
| 785 | Handle<Object> Factory::NewError(Handle<String> message) { |
| 786 | return NewError("$Error", message); |
| 787 | } |
| 788 | |
| 789 | |
| 790 | Handle<Object> Factory::NewError(const char* constructor, |
| 791 | Handle<String> message) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 792 | Handle<String> constr = InternalizeUtf8String(constructor); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 793 | Handle<JSFunction> fun = Handle<JSFunction>( |
| 794 | JSFunction::cast(isolate()->js_builtins_object()-> |
| 795 | GetPropertyNoExceptionThrown(*constr))); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 796 | Handle<Object> argv[] = { message }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 797 | |
| 798 | // Invoke the JavaScript factory method. If an exception is thrown while |
| 799 | // running the factory method, use the exception as the result. |
| 800 | bool caught_exception; |
| 801 | Handle<Object> result = Execution::TryCall(fun, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 802 | isolate()->js_builtins_object(), |
| 803 | ARRAY_SIZE(argv), |
| 804 | argv, |
| 805 | &caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 806 | return result; |
| 807 | } |
| 808 | |
| 809 | |
| 810 | Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
| 811 | InstanceType type, |
| 812 | int instance_size, |
| 813 | Handle<Code> code, |
| 814 | bool force_initial_map) { |
| 815 | // Allocate the function |
| 816 | Handle<JSFunction> function = NewFunction(name, the_hole_value()); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 817 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 818 | // Set up the code pointer in both the shared function info and in |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 819 | // the function itself. |
| 820 | function->shared()->set_code(*code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 821 | function->set_code(*code); |
| 822 | |
| 823 | if (force_initial_map || |
| 824 | type != JS_OBJECT_TYPE || |
| 825 | instance_size != JSObject::kHeaderSize) { |
| 826 | Handle<Map> initial_map = NewMap(type, instance_size); |
| 827 | Handle<JSObject> prototype = NewFunctionPrototype(function); |
| 828 | initial_map->set_prototype(*prototype); |
| 829 | function->set_initial_map(*initial_map); |
| 830 | initial_map->set_constructor(*function); |
| 831 | } else { |
| 832 | ASSERT(!function->has_initial_map()); |
| 833 | ASSERT(!function->has_prototype()); |
| 834 | } |
| 835 | |
| 836 | return function; |
| 837 | } |
| 838 | |
| 839 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 840 | Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name, |
| 841 | InstanceType type, |
| 842 | int instance_size, |
| 843 | Handle<JSObject> prototype, |
| 844 | Handle<Code> code, |
| 845 | bool force_initial_map) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 846 | // Allocate the function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 847 | Handle<JSFunction> function = NewFunction(name, prototype); |
| 848 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 849 | // Set up the code pointer in both the shared function info and in |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 850 | // the function itself. |
| 851 | function->shared()->set_code(*code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 852 | function->set_code(*code); |
| 853 | |
| 854 | if (force_initial_map || |
| 855 | type != JS_OBJECT_TYPE || |
| 856 | instance_size != JSObject::kHeaderSize) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 857 | Handle<Map> initial_map = NewMap(type, |
| 858 | instance_size, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 859 | GetInitialFastElementsKind()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 860 | function->set_initial_map(*initial_map); |
| 861 | initial_map->set_constructor(*function); |
| 862 | } |
| 863 | |
| 864 | // Set function.prototype and give the prototype a constructor |
| 865 | // property that refers to the function. |
| 866 | SetPrototypeProperty(function, prototype); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 867 | // Currently safe because it is only invoked from Genesis. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 868 | CHECK_NOT_EMPTY_HANDLE(isolate(), |
| 869 | JSObject::SetLocalPropertyIgnoreAttributes( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 870 | prototype, constructor_string(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 871 | function, DONT_ENUM)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 872 | return function; |
| 873 | } |
| 874 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 875 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 876 | Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name, |
| 877 | Handle<Code> code) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 878 | Handle<JSFunction> function = NewFunctionWithoutPrototype(name, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 879 | CLASSIC_MODE); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 880 | function->shared()->set_code(*code); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 881 | function->set_code(*code); |
| 882 | ASSERT(!function->has_initial_map()); |
| 883 | ASSERT(!function->has_prototype()); |
| 884 | return function; |
| 885 | } |
| 886 | |
| 887 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 888 | Handle<ScopeInfo> Factory::NewScopeInfo(int length) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 889 | CALL_HEAP_FUNCTION( |
| 890 | isolate(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 891 | isolate()->heap()->AllocateScopeInfo(length), |
| 892 | ScopeInfo); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 896 | Handle<JSObject> Factory::NewExternal(void* value) { |
| 897 | CALL_HEAP_FUNCTION(isolate(), |
| 898 | isolate()->heap()->AllocateExternal(value), |
| 899 | JSObject); |
| 900 | } |
| 901 | |
| 902 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 903 | Handle<Code> Factory::NewCode(const CodeDesc& desc, |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 904 | Code::Flags flags, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 905 | Handle<Object> self_ref, |
| 906 | bool immovable) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 907 | CALL_HEAP_FUNCTION(isolate(), |
| 908 | isolate()->heap()->CreateCode( |
| 909 | desc, flags, self_ref, immovable), |
| 910 | Code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | |
| 914 | Handle<Code> Factory::CopyCode(Handle<Code> code) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 915 | CALL_HEAP_FUNCTION(isolate(), |
| 916 | isolate()->heap()->CopyCode(*code), |
| 917 | Code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 921 | Handle<Code> Factory::CopyCode(Handle<Code> code, Vector<byte> reloc_info) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 922 | CALL_HEAP_FUNCTION(isolate(), |
| 923 | isolate()->heap()->CopyCode(*code, reloc_info), |
| 924 | Code); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 928 | Handle<String> Factory::InternalizedStringFromString(Handle<String> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 929 | CALL_HEAP_FUNCTION(isolate(), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 930 | isolate()->heap()->InternalizeString(*value), String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 934 | Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, |
| 935 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 936 | CALL_HEAP_FUNCTION( |
| 937 | isolate(), |
| 938 | isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 942 | Handle<JSModule> Factory::NewJSModule(Handle<Context> context, |
| 943 | Handle<ScopeInfo> scope_info) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 944 | CALL_HEAP_FUNCTION( |
| 945 | isolate(), |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 946 | isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 950 | Handle<GlobalObject> Factory::NewGlobalObject( |
| 951 | Handle<JSFunction> constructor) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 952 | CALL_HEAP_FUNCTION(isolate(), |
| 953 | isolate()->heap()->AllocateGlobalObject(*constructor), |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 954 | GlobalObject); |
| 955 | } |
| 956 | |
| 957 | |
| 958 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 959 | Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map, |
| 960 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 961 | CALL_HEAP_FUNCTION( |
| 962 | isolate(), |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 963 | isolate()->heap()->AllocateJSObjectFromMap(*map, pretenure), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 964 | JSObject); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 968 | Handle<JSArray> Factory::NewJSArray(int capacity, |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 969 | ElementsKind elements_kind, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 970 | PretenureFlag pretenure) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 971 | if (capacity != 0) { |
| 972 | elements_kind = GetHoleyElementsKind(elements_kind); |
| 973 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 974 | CALL_HEAP_FUNCTION(isolate(), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 975 | isolate()->heap()->AllocateJSArrayAndStorage( |
| 976 | elements_kind, |
| 977 | 0, |
| 978 | capacity, |
| 979 | INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, |
| 980 | pretenure), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 981 | JSArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 985 | Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements, |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 986 | ElementsKind elements_kind, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 987 | PretenureFlag pretenure) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 988 | CALL_HEAP_FUNCTION( |
| 989 | isolate(), |
| 990 | isolate()->heap()->AllocateJSArrayWithElements(*elements, |
| 991 | elements_kind, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 992 | elements->length(), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 993 | pretenure), |
| 994 | JSArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 998 | void Factory::SetElementsCapacityAndLength(Handle<JSArray> array, |
| 999 | int capacity, |
| 1000 | int length) { |
| 1001 | ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 1002 | CALL_HEAP_FUNCTION_VOID( |
| 1003 | isolate(), |
| 1004 | accessor->SetCapacityAndLength(*array, capacity, length)); |
| 1005 | } |
| 1006 | |
| 1007 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1008 | void Factory::SetContent(Handle<JSArray> array, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1009 | Handle<FixedArrayBase> elements) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1010 | CALL_HEAP_FUNCTION_VOID( |
| 1011 | isolate(), |
| 1012 | array->SetContent(*elements)); |
| 1013 | } |
| 1014 | |
| 1015 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1016 | void Factory::EnsureCanContainHeapObjectElements(Handle<JSArray> array) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1017 | CALL_HEAP_FUNCTION_VOID( |
| 1018 | isolate(), |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1019 | array->EnsureCanContainHeapObjectElements()); |
| 1020 | } |
| 1021 | |
| 1022 | |
| 1023 | void Factory::EnsureCanContainElements(Handle<JSArray> array, |
| 1024 | Handle<FixedArrayBase> elements, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1025 | uint32_t length, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1026 | EnsureElementsMode mode) { |
| 1027 | CALL_HEAP_FUNCTION_VOID( |
| 1028 | isolate(), |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1029 | array->EnsureCanContainElements(*elements, length, mode)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1033 | Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, |
| 1034 | Handle<Object> prototype) { |
| 1035 | CALL_HEAP_FUNCTION( |
| 1036 | isolate(), |
| 1037 | isolate()->heap()->AllocateJSProxy(*handler, *prototype), |
| 1038 | JSProxy); |
| 1039 | } |
| 1040 | |
| 1041 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1042 | void Factory::BecomeJSObject(Handle<JSReceiver> object) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1043 | CALL_HEAP_FUNCTION_VOID( |
| 1044 | isolate(), |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1045 | isolate()->heap()->ReinitializeJSReceiver( |
| 1046 | *object, JS_OBJECT_TYPE, JSObject::kHeaderSize)); |
| 1047 | } |
| 1048 | |
| 1049 | |
| 1050 | void Factory::BecomeJSFunction(Handle<JSReceiver> object) { |
| 1051 | CALL_HEAP_FUNCTION_VOID( |
| 1052 | isolate(), |
| 1053 | isolate()->heap()->ReinitializeJSReceiver( |
| 1054 | *object, JS_FUNCTION_TYPE, JSFunction::kSize)); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 1058 | void Factory::SetIdentityHash(Handle<JSObject> object, Smi* hash) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1059 | CALL_HEAP_FUNCTION_VOID( |
| 1060 | isolate(), |
| 1061 | object->SetIdentityHash(hash, ALLOW_CREATION)); |
| 1062 | } |
| 1063 | |
| 1064 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1065 | Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1066 | Handle<String> name, |
| 1067 | int number_of_literals, |
| 1068 | Handle<Code> code, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1069 | Handle<ScopeInfo> scope_info) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1070 | Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name); |
| 1071 | shared->set_code(*code); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1072 | shared->set_scope_info(*scope_info); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1073 | int literals_array_size = number_of_literals; |
| 1074 | // If the function contains object, regexp or array literals, |
| 1075 | // allocate extra space for a literals array prefix containing the |
| 1076 | // context. |
| 1077 | if (number_of_literals > 0) { |
| 1078 | literals_array_size += JSFunction::kLiteralsPrefixSize; |
| 1079 | } |
| 1080 | shared->set_num_literals(literals_array_size); |
| 1081 | return shared; |
| 1082 | } |
| 1083 | |
| 1084 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1085 | Handle<JSMessageObject> Factory::NewJSMessageObject( |
| 1086 | Handle<String> type, |
| 1087 | Handle<JSArray> arguments, |
| 1088 | int start_position, |
| 1089 | int end_position, |
| 1090 | Handle<Object> script, |
| 1091 | Handle<Object> stack_trace, |
| 1092 | Handle<Object> stack_frames) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1093 | CALL_HEAP_FUNCTION(isolate(), |
| 1094 | isolate()->heap()->AllocateJSMessageObject(*type, |
| 1095 | *arguments, |
| 1096 | start_position, |
| 1097 | end_position, |
| 1098 | *script, |
| 1099 | *stack_trace, |
| 1100 | *stack_frames), |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1101 | JSMessageObject); |
| 1102 | } |
| 1103 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1104 | Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(Handle<String> name) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1105 | CALL_HEAP_FUNCTION(isolate(), |
| 1106 | isolate()->heap()->AllocateSharedFunctionInfo(*name), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1107 | SharedFunctionInfo); |
| 1108 | } |
| 1109 | |
| 1110 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1111 | Handle<String> Factory::NumberToString(Handle<Object> number) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1112 | CALL_HEAP_FUNCTION(isolate(), |
| 1113 | isolate()->heap()->NumberToString(*number), String); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1117 | Handle<String> Factory::Uint32ToString(uint32_t value) { |
| 1118 | CALL_HEAP_FUNCTION(isolate(), |
| 1119 | isolate()->heap()->Uint32ToString(value), String); |
| 1120 | } |
| 1121 | |
| 1122 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1123 | Handle<SeededNumberDictionary> Factory::DictionaryAtNumberPut( |
| 1124 | Handle<SeededNumberDictionary> dictionary, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1125 | uint32_t key, |
| 1126 | Handle<Object> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1127 | CALL_HEAP_FUNCTION(isolate(), |
| 1128 | dictionary->AtNumberPut(key, *value), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1129 | SeededNumberDictionary); |
| 1130 | } |
| 1131 | |
| 1132 | |
| 1133 | Handle<UnseededNumberDictionary> Factory::DictionaryAtNumberPut( |
| 1134 | Handle<UnseededNumberDictionary> dictionary, |
| 1135 | uint32_t key, |
| 1136 | Handle<Object> value) { |
| 1137 | CALL_HEAP_FUNCTION(isolate(), |
| 1138 | dictionary->AtNumberPut(key, *value), |
| 1139 | UnseededNumberDictionary); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | |
| 1143 | Handle<JSFunction> Factory::NewFunctionHelper(Handle<String> name, |
| 1144 | Handle<Object> prototype) { |
| 1145 | Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1146 | CALL_HEAP_FUNCTION( |
| 1147 | isolate(), |
| 1148 | isolate()->heap()->AllocateFunction(*isolate()->function_map(), |
| 1149 | *function_share, |
| 1150 | *prototype), |
| 1151 | JSFunction); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
| 1156 | Handle<Object> prototype) { |
| 1157 | Handle<JSFunction> fun = NewFunctionHelper(name, prototype); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1158 | fun->set_context(isolate()->context()->native_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1159 | return fun; |
| 1160 | } |
| 1161 | |
| 1162 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1163 | Handle<JSFunction> Factory::NewFunctionWithoutPrototypeHelper( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1164 | Handle<String> name, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1165 | LanguageMode language_mode) { |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1166 | Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1167 | Handle<Map> map = (language_mode == CLASSIC_MODE) |
| 1168 | ? isolate()->function_without_prototype_map() |
| 1169 | : isolate()->strict_mode_function_without_prototype_map(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1170 | CALL_HEAP_FUNCTION(isolate(), |
| 1171 | isolate()->heap()->AllocateFunction( |
| 1172 | *map, |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1173 | *function_share, |
| 1174 | *the_hole_value()), |
| 1175 | JSFunction); |
| 1176 | } |
| 1177 | |
| 1178 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1179 | Handle<JSFunction> Factory::NewFunctionWithoutPrototype( |
| 1180 | Handle<String> name, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1181 | LanguageMode language_mode) { |
| 1182 | Handle<JSFunction> fun = |
| 1183 | NewFunctionWithoutPrototypeHelper(name, language_mode); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1184 | fun->set_context(isolate()->context()->native_context()); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1185 | return fun; |
| 1186 | } |
| 1187 | |
| 1188 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1189 | Handle<Object> Factory::ToObject(Handle<Object> object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1190 | CALL_HEAP_FUNCTION(isolate(), object->ToObject(), Object); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1194 | Handle<Object> Factory::ToObject(Handle<Object> object, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1195 | Handle<Context> native_context) { |
| 1196 | CALL_HEAP_FUNCTION(isolate(), object->ToObject(*native_context), Object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1200 | #ifdef ENABLE_DEBUGGER_SUPPORT |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1201 | Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) { |
| 1202 | // Get the original code of the function. |
| 1203 | Handle<Code> code(shared->code()); |
| 1204 | |
| 1205 | // Create a copy of the code before allocating the debug info object to avoid |
| 1206 | // allocation while setting up the debug info object. |
| 1207 | Handle<Code> original_code(*Factory::CopyCode(code)); |
| 1208 | |
| 1209 | // Allocate initial fixed array for active break points before allocating the |
| 1210 | // debug info object to avoid allocation while setting up the debug info |
| 1211 | // object. |
| 1212 | Handle<FixedArray> break_points( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1213 | NewFixedArray(Debug::kEstimatedNofBreakPointsInFunction)); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1214 | |
| 1215 | // Create and set up the debug info object. Debug info contains function, a |
| 1216 | // copy of the original code, the executing code and initial fixed array for |
| 1217 | // active break points. |
| 1218 | Handle<DebugInfo> debug_info = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1219 | Handle<DebugInfo>::cast(NewStruct(DEBUG_INFO_TYPE)); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1220 | debug_info->set_shared(*shared); |
| 1221 | debug_info->set_original_code(*original_code); |
| 1222 | debug_info->set_code(*code); |
| 1223 | debug_info->set_break_points(*break_points); |
| 1224 | |
| 1225 | // Link debug info to function. |
| 1226 | shared->set_debug_info(*debug_info); |
| 1227 | |
| 1228 | return debug_info; |
| 1229 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1230 | #endif |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1231 | |
| 1232 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1233 | Handle<JSObject> Factory::NewArgumentsObject(Handle<Object> callee, |
| 1234 | int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1235 | CALL_HEAP_FUNCTION( |
| 1236 | isolate(), |
| 1237 | isolate()->heap()->AllocateArgumentsObject(*callee, length), JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | |
| 1241 | Handle<JSFunction> Factory::CreateApiFunction( |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1242 | Handle<FunctionTemplateInfo> obj, ApiInstanceType instance_type) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1243 | Handle<Code> code = isolate()->builtins()->HandleApiCall(); |
| 1244 | Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1245 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1246 | int internal_field_count = 0; |
| 1247 | if (!obj->instance_template()->IsUndefined()) { |
| 1248 | Handle<ObjectTemplateInfo> instance_template = |
| 1249 | Handle<ObjectTemplateInfo>( |
| 1250 | ObjectTemplateInfo::cast(obj->instance_template())); |
| 1251 | internal_field_count = |
| 1252 | Smi::cast(instance_template->internal_field_count())->value(); |
| 1253 | } |
| 1254 | |
| 1255 | int instance_size = kPointerSize * internal_field_count; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1256 | InstanceType type = INVALID_TYPE; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1257 | switch (instance_type) { |
| 1258 | case JavaScriptObject: |
| 1259 | type = JS_OBJECT_TYPE; |
| 1260 | instance_size += JSObject::kHeaderSize; |
| 1261 | break; |
| 1262 | case InnerGlobalObject: |
| 1263 | type = JS_GLOBAL_OBJECT_TYPE; |
| 1264 | instance_size += JSGlobalObject::kSize; |
| 1265 | break; |
| 1266 | case OuterGlobalObject: |
| 1267 | type = JS_GLOBAL_PROXY_TYPE; |
| 1268 | instance_size += JSGlobalProxy::kSize; |
| 1269 | break; |
| 1270 | default: |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1271 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1272 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1273 | ASSERT(type != INVALID_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1274 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1275 | Handle<JSFunction> result = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 1276 | NewFunction(Factory::empty_string(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1277 | type, |
| 1278 | instance_size, |
| 1279 | code, |
| 1280 | true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1281 | |
| 1282 | // Set length. |
| 1283 | result->shared()->set_length(obj->length()); |
| 1284 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1285 | // Set class name. |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1286 | Handle<Object> class_name = Handle<Object>(obj->class_name(), isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1287 | if (class_name->IsString()) { |
| 1288 | result->shared()->set_instance_class_name(*class_name); |
| 1289 | result->shared()->set_name(*class_name); |
| 1290 | } |
| 1291 | |
| 1292 | Handle<Map> map = Handle<Map>(result->initial_map()); |
| 1293 | |
| 1294 | // Mark as undetectable if needed. |
| 1295 | if (obj->undetectable()) { |
| 1296 | map->set_is_undetectable(); |
| 1297 | } |
| 1298 | |
| 1299 | // Mark as hidden for the __proto__ accessor if needed. |
| 1300 | if (obj->hidden_prototype()) { |
| 1301 | map->set_is_hidden_prototype(); |
| 1302 | } |
| 1303 | |
| 1304 | // Mark as needs_access_check if needed. |
| 1305 | if (obj->needs_access_check()) { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1306 | map->set_is_access_check_needed(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1309 | // Set interceptor information in the map. |
| 1310 | if (!obj->named_property_handler()->IsUndefined()) { |
| 1311 | map->set_has_named_interceptor(); |
| 1312 | } |
| 1313 | if (!obj->indexed_property_handler()->IsUndefined()) { |
| 1314 | map->set_has_indexed_interceptor(); |
| 1315 | } |
| 1316 | |
| 1317 | // Set instance call-as-function information in the map. |
| 1318 | if (!obj->instance_call_handler()->IsUndefined()) { |
| 1319 | map->set_has_instance_call_handler(); |
| 1320 | } |
| 1321 | |
| 1322 | result->shared()->set_function_data(*obj); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1323 | result->shared()->set_construct_stub(*construct_stub); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1324 | result->shared()->DontAdaptArguments(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1325 | |
| 1326 | // Recursively copy parent templates' accessors, 'data' may be modified. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1327 | int max_number_of_additional_properties = 0; |
| 1328 | FunctionTemplateInfo* info = *obj; |
| 1329 | while (true) { |
| 1330 | Object* props = info->property_accessors(); |
| 1331 | if (!props->IsUndefined()) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1332 | Handle<Object> props_handle(props, isolate()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1333 | NeanderArray props_array(props_handle); |
| 1334 | max_number_of_additional_properties += props_array.length(); |
| 1335 | } |
| 1336 | Object* parent = info->parent_template(); |
| 1337 | if (parent->IsUndefined()) break; |
| 1338 | info = FunctionTemplateInfo::cast(parent); |
| 1339 | } |
| 1340 | |
| 1341 | Map::EnsureDescriptorSlack(map, max_number_of_additional_properties); |
| 1342 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1343 | while (true) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1344 | Handle<Object> props = Handle<Object>(obj->property_accessors(), |
| 1345 | isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1346 | if (!props->IsUndefined()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1347 | Map::AppendCallbackDescriptors(map, props); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1348 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1349 | Handle<Object> parent = Handle<Object>(obj->parent_template(), isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1350 | if (parent->IsUndefined()) break; |
| 1351 | obj = Handle<FunctionTemplateInfo>::cast(parent); |
| 1352 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1353 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1354 | ASSERT(result->shared()->IsApiFunction()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1355 | return result; |
| 1356 | } |
| 1357 | |
| 1358 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1359 | Handle<MapCache> Factory::NewMapCache(int at_least_space_for) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1360 | CALL_HEAP_FUNCTION(isolate(), |
| 1361 | MapCache::Allocate(at_least_space_for), MapCache); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1365 | MUST_USE_RESULT static MaybeObject* UpdateMapCacheWith(Context* context, |
| 1366 | FixedArray* keys, |
| 1367 | Map* map) { |
| 1368 | Object* result; |
| 1369 | { MaybeObject* maybe_result = |
| 1370 | MapCache::cast(context->map_cache())->Put(keys, map); |
| 1371 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1372 | } |
| 1373 | context->set_map_cache(MapCache::cast(result)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1374 | return result; |
| 1375 | } |
| 1376 | |
| 1377 | |
| 1378 | Handle<MapCache> Factory::AddToMapCache(Handle<Context> context, |
| 1379 | Handle<FixedArray> keys, |
| 1380 | Handle<Map> map) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1381 | CALL_HEAP_FUNCTION(isolate(), |
| 1382 | UpdateMapCacheWith(*context, *keys, *map), MapCache); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | |
| 1386 | Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, |
| 1387 | Handle<FixedArray> keys) { |
| 1388 | if (context->map_cache()->IsUndefined()) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1389 | // Allocate the new map cache for the native context. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1390 | Handle<MapCache> new_cache = NewMapCache(24); |
| 1391 | context->set_map_cache(*new_cache); |
| 1392 | } |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1393 | // Check to see whether there is a matching element in the cache. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1394 | Handle<MapCache> cache = |
| 1395 | Handle<MapCache>(MapCache::cast(context->map_cache())); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1396 | Handle<Object> result = Handle<Object>(cache->Lookup(*keys), isolate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1397 | if (result->IsMap()) return Handle<Map>::cast(result); |
| 1398 | // Create a new map and add it to the cache. |
| 1399 | Handle<Map> map = |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1400 | CopyMap(Handle<Map>(context->object_function()->initial_map()), |
| 1401 | keys->length()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1402 | AddToMapCache(context, keys, map); |
| 1403 | return Handle<Map>(map); |
| 1404 | } |
| 1405 | |
| 1406 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1407 | void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, |
| 1408 | JSRegExp::Type type, |
| 1409 | Handle<String> source, |
| 1410 | JSRegExp::Flags flags, |
| 1411 | Handle<Object> data) { |
| 1412 | Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize); |
| 1413 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1414 | store->set(JSRegExp::kTagIndex, Smi::FromInt(type)); |
| 1415 | store->set(JSRegExp::kSourceIndex, *source); |
| 1416 | store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value())); |
| 1417 | store->set(JSRegExp::kAtomPatternIndex, *data); |
| 1418 | regexp->set_data(*store); |
| 1419 | } |
| 1420 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1421 | void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp, |
| 1422 | JSRegExp::Type type, |
| 1423 | Handle<String> source, |
| 1424 | JSRegExp::Flags flags, |
| 1425 | int capture_count) { |
| 1426 | Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1427 | Smi* uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1428 | store->set(JSRegExp::kTagIndex, Smi::FromInt(type)); |
| 1429 | store->set(JSRegExp::kSourceIndex, *source); |
| 1430 | store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value())); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1431 | store->set(JSRegExp::kIrregexpASCIICodeIndex, uninitialized); |
| 1432 | store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized); |
| 1433 | store->set(JSRegExp::kIrregexpASCIICodeSavedIndex, uninitialized); |
| 1434 | store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1435 | store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0)); |
| 1436 | store->set(JSRegExp::kIrregexpCaptureCountIndex, |
| 1437 | Smi::FromInt(capture_count)); |
| 1438 | regexp->set_data(*store); |
| 1439 | } |
| 1440 | |
| 1441 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1442 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1443 | void Factory::ConfigureInstance(Handle<FunctionTemplateInfo> desc, |
| 1444 | Handle<JSObject> instance, |
| 1445 | bool* pending_exception) { |
| 1446 | // Configure the instance by adding the properties specified by the |
| 1447 | // instance template. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1448 | Handle<Object> instance_template(desc->instance_template(), isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1449 | if (!instance_template->IsUndefined()) { |
| 1450 | Execution::ConfigureInstance(instance, |
| 1451 | instance_template, |
| 1452 | pending_exception); |
| 1453 | } else { |
| 1454 | *pending_exception = false; |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1459 | Handle<Object> Factory::GlobalConstantFor(Handle<String> name) { |
| 1460 | Heap* h = isolate()->heap(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 1461 | if (name->Equals(h->undefined_string())) return undefined_value(); |
| 1462 | if (name->Equals(h->nan_string())) return nan_value(); |
| 1463 | if (name->Equals(h->infinity_string())) return infinity_value(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1464 | return Handle<Object>::null(); |
| 1465 | } |
| 1466 | |
| 1467 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1468 | Handle<Object> Factory::ToBoolean(bool value) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1469 | return value ? true_value() : false_value(); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1473 | } } // namespace v8::internal |