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 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame^] | 73 | Handle<NameDictionary> Factory::NewNameDictionary(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(), |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame^] | 76 | NameDictionary::Allocate(at_least_space_for), |
| 77 | NameDictionary); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 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 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame^] | 372 | Handle<DeclaredAccessorDescriptor> Factory::NewDeclaredAccessorDescriptor() { |
| 373 | return Handle<DeclaredAccessorDescriptor>::cast( |
| 374 | NewStruct(DECLARED_ACCESSOR_DESCRIPTOR_TYPE)); |
| 375 | } |
| 376 | |
| 377 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 378 | Handle<DeclaredAccessorInfo> Factory::NewDeclaredAccessorInfo() { |
| 379 | Handle<DeclaredAccessorInfo> info = |
| 380 | Handle<DeclaredAccessorInfo>::cast( |
| 381 | NewStruct(DECLARED_ACCESSOR_INFO_TYPE)); |
| 382 | info->set_flag(0); // Must clear the flag, it was initialized as undefined. |
| 383 | return info; |
| 384 | } |
| 385 | |
| 386 | |
| 387 | Handle<ExecutableAccessorInfo> Factory::NewExecutableAccessorInfo() { |
| 388 | Handle<ExecutableAccessorInfo> info = |
| 389 | Handle<ExecutableAccessorInfo>::cast( |
| 390 | NewStruct(EXECUTABLE_ACCESSOR_INFO_TYPE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 391 | info->set_flag(0); // Must clear the flag, it was initialized as undefined. |
| 392 | return info; |
| 393 | } |
| 394 | |
| 395 | |
| 396 | Handle<Script> Factory::NewScript(Handle<String> source) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 397 | // Generate id for this script. |
| 398 | int id; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 399 | Heap* heap = isolate()->heap(); |
| 400 | if (heap->last_script_id()->IsUndefined()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 401 | // Script ids start from one. |
| 402 | id = 1; |
| 403 | } else { |
| 404 | // Increment id, wrap when positive smi is exhausted. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 405 | id = Smi::cast(heap->last_script_id())->value(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 406 | id++; |
| 407 | if (!Smi::IsValid(id)) { |
| 408 | id = 0; |
| 409 | } |
| 410 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 411 | heap->SetLastScriptId(Smi::FromInt(id)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 412 | |
| 413 | // Create and initialize script object. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 414 | Handle<Foreign> wrapper = NewForeign(0, TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 415 | Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE)); |
| 416 | script->set_source(*source); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 417 | script->set_name(heap->undefined_value()); |
| 418 | script->set_id(heap->last_script_id()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 419 | script->set_line_offset(Smi::FromInt(0)); |
| 420 | script->set_column_offset(Smi::FromInt(0)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 421 | script->set_data(heap->undefined_value()); |
| 422 | script->set_context_data(heap->undefined_value()); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 423 | script->set_type(Smi::FromInt(Script::TYPE_NORMAL)); |
| 424 | script->set_compilation_type(Smi::FromInt(Script::COMPILATION_TYPE_HOST)); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 425 | script->set_compilation_state( |
| 426 | Smi::FromInt(Script::COMPILATION_STATE_INITIAL)); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 427 | script->set_wrapper(*wrapper); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 428 | script->set_line_ends(heap->undefined_value()); |
| 429 | script->set_eval_from_shared(heap->undefined_value()); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 430 | script->set_eval_from_instructions_offset(Smi::FromInt(0)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 431 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 432 | return script; |
| 433 | } |
| 434 | |
| 435 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 436 | Handle<Foreign> Factory::NewForeign(Address addr, PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 437 | CALL_HEAP_FUNCTION(isolate(), |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 438 | isolate()->heap()->AllocateForeign(addr, pretenure), |
| 439 | Foreign); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 443 | Handle<Foreign> Factory::NewForeign(const AccessorDescriptor* desc) { |
| 444 | return NewForeign((Address) desc, TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 448 | Handle<ByteArray> Factory::NewByteArray(int length, PretenureFlag pretenure) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 449 | ASSERT(0 <= length); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 450 | CALL_HEAP_FUNCTION( |
| 451 | isolate(), |
| 452 | isolate()->heap()->AllocateByteArray(length, pretenure), |
| 453 | ByteArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 457 | Handle<ExternalArray> Factory::NewExternalArray(int length, |
| 458 | ExternalArrayType array_type, |
| 459 | void* external_pointer, |
| 460 | PretenureFlag pretenure) { |
| 461 | ASSERT(0 <= length); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 462 | CALL_HEAP_FUNCTION( |
| 463 | isolate(), |
| 464 | isolate()->heap()->AllocateExternalArray(length, |
| 465 | array_type, |
| 466 | external_pointer, |
| 467 | pretenure), |
| 468 | ExternalArray); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 472 | Handle<JSGlobalPropertyCell> Factory::NewJSGlobalPropertyCell( |
| 473 | Handle<Object> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 474 | CALL_HEAP_FUNCTION( |
| 475 | isolate(), |
| 476 | isolate()->heap()->AllocateJSGlobalPropertyCell(*value), |
| 477 | JSGlobalPropertyCell); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 481 | Handle<Map> Factory::NewMap(InstanceType type, |
| 482 | int instance_size, |
| 483 | ElementsKind elements_kind) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 484 | CALL_HEAP_FUNCTION( |
| 485 | isolate(), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 486 | isolate()->heap()->AllocateMap(type, instance_size, elements_kind), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 487 | Map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | |
| 491 | Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 492 | CALL_HEAP_FUNCTION( |
| 493 | isolate(), |
| 494 | isolate()->heap()->AllocateFunctionPrototype(*function), |
| 495 | JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 499 | Handle<Map> Factory::CopyWithPreallocatedFieldDescriptors(Handle<Map> src) { |
| 500 | CALL_HEAP_FUNCTION( |
| 501 | isolate(), src->CopyWithPreallocatedFieldDescriptors(), Map); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 505 | Handle<Map> Factory::CopyMap(Handle<Map> src, |
| 506 | int extra_inobject_properties) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 507 | Handle<Map> copy = CopyWithPreallocatedFieldDescriptors(src); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 508 | // Check that we do not overflow the instance size when adding the |
| 509 | // extra inobject properties. |
| 510 | int instance_size_delta = extra_inobject_properties * kPointerSize; |
| 511 | int max_instance_size_delta = |
| 512 | JSObject::kMaxInstanceSize - copy->instance_size(); |
| 513 | if (instance_size_delta > max_instance_size_delta) { |
| 514 | // If the instance size overflows, we allocate as many properties |
| 515 | // as we can as inobject properties. |
| 516 | instance_size_delta = max_instance_size_delta; |
| 517 | extra_inobject_properties = max_instance_size_delta >> kPointerSizeLog2; |
| 518 | } |
| 519 | // Adjust the map with the extra inobject properties. |
| 520 | int inobject_properties = |
| 521 | copy->inobject_properties() + extra_inobject_properties; |
| 522 | copy->set_inobject_properties(inobject_properties); |
| 523 | copy->set_unused_property_fields(inobject_properties); |
| 524 | copy->set_instance_size(copy->instance_size() + instance_size_delta); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 525 | copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 526 | return copy; |
| 527 | } |
| 528 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 529 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 530 | Handle<Map> Factory::CopyMap(Handle<Map> src) { |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 531 | CALL_HEAP_FUNCTION(isolate(), src->Copy(), Map); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 535 | Handle<Map> Factory::GetElementsTransitionMap( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 536 | Handle<JSObject> src, |
| 537 | ElementsKind elements_kind) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 538 | Isolate* i = isolate(); |
| 539 | CALL_HEAP_FUNCTION(i, |
| 540 | src->GetElementsTransitionMap(i, elements_kind), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 541 | Map); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 546 | CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 550 | Handle<FixedArray> Factory::CopySizeFixedArray(Handle<FixedArray> array, |
| 551 | int new_length) { |
| 552 | CALL_HEAP_FUNCTION(isolate(), array->CopySize(new_length), FixedArray); |
| 553 | } |
| 554 | |
| 555 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 556 | Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray( |
| 557 | Handle<FixedDoubleArray> array) { |
| 558 | CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray); |
| 559 | } |
| 560 | |
| 561 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 562 | Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo( |
| 563 | Handle<SharedFunctionInfo> function_info, |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 564 | Handle<Map> function_map, |
| 565 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 566 | CALL_HEAP_FUNCTION( |
| 567 | isolate(), |
| 568 | isolate()->heap()->AllocateFunction(*function_map, |
| 569 | *function_info, |
| 570 | isolate()->heap()->the_hole_value(), |
| 571 | pretenure), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 572 | JSFunction); |
| 573 | } |
| 574 | |
| 575 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 576 | Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
| 577 | Handle<SharedFunctionInfo> function_info, |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 578 | Handle<Context> context, |
| 579 | PretenureFlag pretenure) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 580 | Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 581 | function_info, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 582 | function_info->is_classic_mode() |
| 583 | ? isolate()->function_map() |
| 584 | : isolate()->strict_mode_function_map(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 585 | pretenure); |
| 586 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 587 | if (function_info->ic_age() != isolate()->heap()->global_ic_age()) { |
| 588 | function_info->ResetForNewContext(isolate()->heap()->global_ic_age()); |
| 589 | } |
| 590 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 591 | result->set_context(*context); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 592 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 593 | int index = function_info->SearchOptimizedCodeMap(context->native_context()); |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 594 | if (!function_info->bound() && index < 0) { |
| 595 | int number_of_literals = function_info->num_literals(); |
| 596 | Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure); |
| 597 | if (number_of_literals > 0) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 598 | // Store the native context in the literals array prefix. This |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 599 | // context will be used when creating object, regexp and array |
| 600 | // literals in this function. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 601 | literals->set(JSFunction::kLiteralNativeContextIndex, |
| 602 | context->native_context()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 603 | } |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 604 | result->set_literals(*literals); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 605 | } |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 606 | |
| 607 | if (index > 0) { |
| 608 | // Caching of optimized code enabled and optimized code found. |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 609 | function_info->InstallFromOptimizedCodeMap(*result, index); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 610 | return result; |
| 611 | } |
| 612 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 613 | if (V8::UseCrankshaft() && |
| 614 | FLAG_always_opt && |
| 615 | result->is_compiled() && |
| 616 | !function_info->is_toplevel() && |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 617 | function_info->allows_lazy_compilation() && |
| 618 | !function_info->optimization_disabled()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 619 | result->MarkForLazyRecompilation(); |
| 620 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 621 | return result; |
| 622 | } |
| 623 | |
| 624 | |
| 625 | Handle<Object> Factory::NewNumber(double value, |
| 626 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 627 | CALL_HEAP_FUNCTION( |
| 628 | isolate(), |
| 629 | isolate()->heap()->NumberFromDouble(value, pretenure), Object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 633 | Handle<Object> Factory::NewNumberFromInt(int32_t value, |
| 634 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 635 | CALL_HEAP_FUNCTION( |
| 636 | isolate(), |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 637 | isolate()->heap()->NumberFromInt32(value, pretenure), Object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 641 | Handle<Object> Factory::NewNumberFromUint(uint32_t value, |
| 642 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 643 | CALL_HEAP_FUNCTION( |
| 644 | isolate(), |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 645 | isolate()->heap()->NumberFromUint32(value, pretenure), Object); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 649 | Handle<JSObject> Factory::NewNeanderObject() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 650 | CALL_HEAP_FUNCTION( |
| 651 | isolate(), |
| 652 | isolate()->heap()->AllocateJSObjectFromMap( |
| 653 | isolate()->heap()->neander_map()), |
| 654 | JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | |
| 658 | Handle<Object> Factory::NewTypeError(const char* type, |
| 659 | Vector< Handle<Object> > args) { |
| 660 | return NewError("MakeTypeError", type, args); |
| 661 | } |
| 662 | |
| 663 | |
| 664 | Handle<Object> Factory::NewTypeError(Handle<String> message) { |
| 665 | return NewError("$TypeError", message); |
| 666 | } |
| 667 | |
| 668 | |
| 669 | Handle<Object> Factory::NewRangeError(const char* type, |
| 670 | Vector< Handle<Object> > args) { |
| 671 | return NewError("MakeRangeError", type, args); |
| 672 | } |
| 673 | |
| 674 | |
| 675 | Handle<Object> Factory::NewRangeError(Handle<String> message) { |
| 676 | return NewError("$RangeError", message); |
| 677 | } |
| 678 | |
| 679 | |
| 680 | Handle<Object> Factory::NewSyntaxError(const char* type, Handle<JSArray> args) { |
| 681 | return NewError("MakeSyntaxError", type, args); |
| 682 | } |
| 683 | |
| 684 | |
| 685 | Handle<Object> Factory::NewSyntaxError(Handle<String> message) { |
| 686 | return NewError("$SyntaxError", message); |
| 687 | } |
| 688 | |
| 689 | |
| 690 | Handle<Object> Factory::NewReferenceError(const char* type, |
| 691 | Vector< Handle<Object> > args) { |
| 692 | return NewError("MakeReferenceError", type, args); |
| 693 | } |
| 694 | |
| 695 | |
| 696 | Handle<Object> Factory::NewReferenceError(Handle<String> message) { |
| 697 | return NewError("$ReferenceError", message); |
| 698 | } |
| 699 | |
| 700 | |
| 701 | Handle<Object> Factory::NewError(const char* maker, const char* type, |
| 702 | Vector< Handle<Object> > args) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 703 | v8::HandleScope scope; // Instantiate a closeable HandleScope for EscapeFrom. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 704 | Handle<FixedArray> array = NewFixedArray(args.length()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 705 | for (int i = 0; i < args.length(); i++) { |
| 706 | array->set(i, *args[i]); |
| 707 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 708 | Handle<JSArray> object = NewJSArrayWithElements(array); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 709 | Handle<Object> result = NewError(maker, type, object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 710 | return result.EscapeFrom(&scope); |
| 711 | } |
| 712 | |
| 713 | |
| 714 | Handle<Object> Factory::NewEvalError(const char* type, |
| 715 | Vector< Handle<Object> > args) { |
| 716 | return NewError("MakeEvalError", type, args); |
| 717 | } |
| 718 | |
| 719 | |
| 720 | Handle<Object> Factory::NewError(const char* type, |
| 721 | Vector< Handle<Object> > args) { |
| 722 | return NewError("MakeError", type, args); |
| 723 | } |
| 724 | |
| 725 | |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 726 | Handle<String> Factory::EmergencyNewError(const char* type, |
| 727 | Handle<JSArray> args) { |
| 728 | const int kBufferSize = 1000; |
| 729 | char buffer[kBufferSize]; |
| 730 | size_t space = kBufferSize; |
| 731 | char* p = &buffer[0]; |
| 732 | |
| 733 | Vector<char> v(buffer, kBufferSize); |
| 734 | OS::StrNCpy(v, type, space); |
| 735 | space -= Min(space, strlen(type)); |
| 736 | p = &buffer[kBufferSize] - space; |
| 737 | |
| 738 | for (unsigned i = 0; i < ARRAY_SIZE(args); i++) { |
| 739 | if (space > 0) { |
| 740 | *p++ = ' '; |
| 741 | space--; |
| 742 | if (space > 0) { |
| 743 | MaybeObject* maybe_arg = args->GetElement(i); |
| 744 | Handle<String> arg_str(reinterpret_cast<String*>(maybe_arg)); |
| 745 | const char* arg = *arg_str->ToCString(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 746 | Vector<char> v2(p, static_cast<int>(space)); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 747 | OS::StrNCpy(v2, arg, space); |
| 748 | space -= Min(space, strlen(arg)); |
| 749 | p = &buffer[kBufferSize] - space; |
| 750 | } |
| 751 | } |
| 752 | } |
| 753 | if (space > 0) { |
| 754 | *p = '\0'; |
| 755 | } else { |
| 756 | buffer[kBufferSize - 1] = '\0'; |
| 757 | } |
| 758 | Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED); |
| 759 | return error_string; |
| 760 | } |
| 761 | |
| 762 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 763 | Handle<Object> Factory::NewError(const char* maker, |
| 764 | const char* type, |
| 765 | Handle<JSArray> args) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 766 | Handle<String> make_str = InternalizeUtf8String(maker); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 767 | Handle<Object> fun_obj( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 768 | isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str), |
| 769 | isolate()); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 770 | // If the builtins haven't been properly configured yet this error |
| 771 | // constructor may not have been defined. Bail out. |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 772 | if (!fun_obj->IsJSFunction()) { |
| 773 | return EmergencyNewError(type, args); |
| 774 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 775 | Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 776 | Handle<Object> type_obj = InternalizeUtf8String(type); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 777 | Handle<Object> argv[] = { type_obj, args }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 778 | |
| 779 | // Invoke the JavaScript factory method. If an exception is thrown while |
| 780 | // running the factory method, use the exception as the result. |
| 781 | bool caught_exception; |
| 782 | Handle<Object> result = Execution::TryCall(fun, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 783 | isolate()->js_builtins_object(), |
| 784 | ARRAY_SIZE(argv), |
| 785 | argv, |
| 786 | &caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 787 | return result; |
| 788 | } |
| 789 | |
| 790 | |
| 791 | Handle<Object> Factory::NewError(Handle<String> message) { |
| 792 | return NewError("$Error", message); |
| 793 | } |
| 794 | |
| 795 | |
| 796 | Handle<Object> Factory::NewError(const char* constructor, |
| 797 | Handle<String> message) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 798 | Handle<String> constr = InternalizeUtf8String(constructor); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 799 | Handle<JSFunction> fun = Handle<JSFunction>( |
| 800 | JSFunction::cast(isolate()->js_builtins_object()-> |
| 801 | GetPropertyNoExceptionThrown(*constr))); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 802 | Handle<Object> argv[] = { message }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 803 | |
| 804 | // Invoke the JavaScript factory method. If an exception is thrown while |
| 805 | // running the factory method, use the exception as the result. |
| 806 | bool caught_exception; |
| 807 | Handle<Object> result = Execution::TryCall(fun, |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 808 | isolate()->js_builtins_object(), |
| 809 | ARRAY_SIZE(argv), |
| 810 | argv, |
| 811 | &caught_exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 812 | return result; |
| 813 | } |
| 814 | |
| 815 | |
| 816 | Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
| 817 | InstanceType type, |
| 818 | int instance_size, |
| 819 | Handle<Code> code, |
| 820 | bool force_initial_map) { |
| 821 | // Allocate the function |
| 822 | Handle<JSFunction> function = NewFunction(name, the_hole_value()); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 823 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 824 | // 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] | 825 | // the function itself. |
| 826 | function->shared()->set_code(*code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 827 | function->set_code(*code); |
| 828 | |
| 829 | if (force_initial_map || |
| 830 | type != JS_OBJECT_TYPE || |
| 831 | instance_size != JSObject::kHeaderSize) { |
| 832 | Handle<Map> initial_map = NewMap(type, instance_size); |
| 833 | Handle<JSObject> prototype = NewFunctionPrototype(function); |
| 834 | initial_map->set_prototype(*prototype); |
| 835 | function->set_initial_map(*initial_map); |
| 836 | initial_map->set_constructor(*function); |
| 837 | } else { |
| 838 | ASSERT(!function->has_initial_map()); |
| 839 | ASSERT(!function->has_prototype()); |
| 840 | } |
| 841 | |
| 842 | return function; |
| 843 | } |
| 844 | |
| 845 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 846 | Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name, |
| 847 | InstanceType type, |
| 848 | int instance_size, |
| 849 | Handle<JSObject> prototype, |
| 850 | Handle<Code> code, |
| 851 | bool force_initial_map) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 852 | // Allocate the function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 853 | Handle<JSFunction> function = NewFunction(name, prototype); |
| 854 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 855 | // 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] | 856 | // the function itself. |
| 857 | function->shared()->set_code(*code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | function->set_code(*code); |
| 859 | |
| 860 | if (force_initial_map || |
| 861 | type != JS_OBJECT_TYPE || |
| 862 | instance_size != JSObject::kHeaderSize) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 863 | Handle<Map> initial_map = NewMap(type, |
| 864 | instance_size, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 865 | GetInitialFastElementsKind()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 866 | function->set_initial_map(*initial_map); |
| 867 | initial_map->set_constructor(*function); |
| 868 | } |
| 869 | |
| 870 | // Set function.prototype and give the prototype a constructor |
| 871 | // property that refers to the function. |
| 872 | SetPrototypeProperty(function, prototype); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 873 | // Currently safe because it is only invoked from Genesis. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 874 | CHECK_NOT_EMPTY_HANDLE(isolate(), |
| 875 | JSObject::SetLocalPropertyIgnoreAttributes( |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 876 | prototype, constructor_string(), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 877 | function, DONT_ENUM)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 878 | return function; |
| 879 | } |
| 880 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 881 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 882 | Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name, |
| 883 | Handle<Code> code) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 884 | Handle<JSFunction> function = NewFunctionWithoutPrototype(name, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 885 | CLASSIC_MODE); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 886 | function->shared()->set_code(*code); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 887 | function->set_code(*code); |
| 888 | ASSERT(!function->has_initial_map()); |
| 889 | ASSERT(!function->has_prototype()); |
| 890 | return function; |
| 891 | } |
| 892 | |
| 893 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 894 | Handle<ScopeInfo> Factory::NewScopeInfo(int length) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 895 | CALL_HEAP_FUNCTION( |
| 896 | isolate(), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 897 | isolate()->heap()->AllocateScopeInfo(length), |
| 898 | ScopeInfo); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 902 | Handle<JSObject> Factory::NewExternal(void* value) { |
| 903 | CALL_HEAP_FUNCTION(isolate(), |
| 904 | isolate()->heap()->AllocateExternal(value), |
| 905 | JSObject); |
| 906 | } |
| 907 | |
| 908 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 909 | Handle<Code> Factory::NewCode(const CodeDesc& desc, |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 910 | Code::Flags flags, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 911 | Handle<Object> self_ref, |
| 912 | bool immovable) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 913 | CALL_HEAP_FUNCTION(isolate(), |
| 914 | isolate()->heap()->CreateCode( |
| 915 | desc, flags, self_ref, immovable), |
| 916 | Code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | |
| 920 | Handle<Code> Factory::CopyCode(Handle<Code> code) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 921 | CALL_HEAP_FUNCTION(isolate(), |
| 922 | isolate()->heap()->CopyCode(*code), |
| 923 | Code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 927 | Handle<Code> Factory::CopyCode(Handle<Code> code, Vector<byte> reloc_info) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 928 | CALL_HEAP_FUNCTION(isolate(), |
| 929 | isolate()->heap()->CopyCode(*code, reloc_info), |
| 930 | Code); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 934 | Handle<String> Factory::InternalizedStringFromString(Handle<String> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 935 | CALL_HEAP_FUNCTION(isolate(), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 936 | isolate()->heap()->InternalizeString(*value), String); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 940 | Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, |
| 941 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 942 | CALL_HEAP_FUNCTION( |
| 943 | isolate(), |
| 944 | isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 948 | Handle<JSModule> Factory::NewJSModule(Handle<Context> context, |
| 949 | Handle<ScopeInfo> scope_info) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 950 | CALL_HEAP_FUNCTION( |
| 951 | isolate(), |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 952 | isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 956 | Handle<GlobalObject> Factory::NewGlobalObject( |
| 957 | Handle<JSFunction> constructor) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 958 | CALL_HEAP_FUNCTION(isolate(), |
| 959 | isolate()->heap()->AllocateGlobalObject(*constructor), |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 960 | GlobalObject); |
| 961 | } |
| 962 | |
| 963 | |
| 964 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 965 | Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map, |
| 966 | PretenureFlag pretenure) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 967 | CALL_HEAP_FUNCTION( |
| 968 | isolate(), |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 969 | isolate()->heap()->AllocateJSObjectFromMap(*map, pretenure), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 970 | JSObject); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 974 | Handle<JSArray> Factory::NewJSArray(int capacity, |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 975 | ElementsKind elements_kind, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 976 | PretenureFlag pretenure) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 977 | if (capacity != 0) { |
| 978 | elements_kind = GetHoleyElementsKind(elements_kind); |
| 979 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 980 | CALL_HEAP_FUNCTION(isolate(), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 981 | isolate()->heap()->AllocateJSArrayAndStorage( |
| 982 | elements_kind, |
| 983 | 0, |
| 984 | capacity, |
| 985 | INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, |
| 986 | pretenure), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 987 | JSArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 991 | Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements, |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 992 | ElementsKind elements_kind, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 993 | PretenureFlag pretenure) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 994 | CALL_HEAP_FUNCTION( |
| 995 | isolate(), |
| 996 | isolate()->heap()->AllocateJSArrayWithElements(*elements, |
| 997 | elements_kind, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 998 | elements->length(), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 999 | pretenure), |
| 1000 | JSArray); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1004 | void Factory::SetElementsCapacityAndLength(Handle<JSArray> array, |
| 1005 | int capacity, |
| 1006 | int length) { |
| 1007 | ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 1008 | CALL_HEAP_FUNCTION_VOID( |
| 1009 | isolate(), |
| 1010 | accessor->SetCapacityAndLength(*array, capacity, length)); |
| 1011 | } |
| 1012 | |
| 1013 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1014 | void Factory::SetContent(Handle<JSArray> array, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1015 | Handle<FixedArrayBase> elements) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1016 | CALL_HEAP_FUNCTION_VOID( |
| 1017 | isolate(), |
| 1018 | array->SetContent(*elements)); |
| 1019 | } |
| 1020 | |
| 1021 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1022 | void Factory::EnsureCanContainHeapObjectElements(Handle<JSArray> array) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1023 | CALL_HEAP_FUNCTION_VOID( |
| 1024 | isolate(), |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1025 | array->EnsureCanContainHeapObjectElements()); |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | void Factory::EnsureCanContainElements(Handle<JSArray> array, |
| 1030 | Handle<FixedArrayBase> elements, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1031 | uint32_t length, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1032 | EnsureElementsMode mode) { |
| 1033 | CALL_HEAP_FUNCTION_VOID( |
| 1034 | isolate(), |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1035 | array->EnsureCanContainElements(*elements, length, mode)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1039 | Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, |
| 1040 | Handle<Object> prototype) { |
| 1041 | CALL_HEAP_FUNCTION( |
| 1042 | isolate(), |
| 1043 | isolate()->heap()->AllocateJSProxy(*handler, *prototype), |
| 1044 | JSProxy); |
| 1045 | } |
| 1046 | |
| 1047 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1048 | void Factory::BecomeJSObject(Handle<JSReceiver> object) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1049 | CALL_HEAP_FUNCTION_VOID( |
| 1050 | isolate(), |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1051 | isolate()->heap()->ReinitializeJSReceiver( |
| 1052 | *object, JS_OBJECT_TYPE, JSObject::kHeaderSize)); |
| 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | void Factory::BecomeJSFunction(Handle<JSReceiver> object) { |
| 1057 | CALL_HEAP_FUNCTION_VOID( |
| 1058 | isolate(), |
| 1059 | isolate()->heap()->ReinitializeJSReceiver( |
| 1060 | *object, JS_FUNCTION_TYPE, JSFunction::kSize)); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 1064 | void Factory::SetIdentityHash(Handle<JSObject> object, Smi* hash) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1065 | CALL_HEAP_FUNCTION_VOID( |
| 1066 | isolate(), |
| 1067 | object->SetIdentityHash(hash, ALLOW_CREATION)); |
| 1068 | } |
| 1069 | |
| 1070 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1071 | Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1072 | Handle<String> name, |
| 1073 | int number_of_literals, |
| 1074 | Handle<Code> code, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1075 | Handle<ScopeInfo> scope_info) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1076 | Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name); |
| 1077 | shared->set_code(*code); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1078 | shared->set_scope_info(*scope_info); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1079 | int literals_array_size = number_of_literals; |
| 1080 | // If the function contains object, regexp or array literals, |
| 1081 | // allocate extra space for a literals array prefix containing the |
| 1082 | // context. |
| 1083 | if (number_of_literals > 0) { |
| 1084 | literals_array_size += JSFunction::kLiteralsPrefixSize; |
| 1085 | } |
| 1086 | shared->set_num_literals(literals_array_size); |
| 1087 | return shared; |
| 1088 | } |
| 1089 | |
| 1090 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1091 | Handle<JSMessageObject> Factory::NewJSMessageObject( |
| 1092 | Handle<String> type, |
| 1093 | Handle<JSArray> arguments, |
| 1094 | int start_position, |
| 1095 | int end_position, |
| 1096 | Handle<Object> script, |
| 1097 | Handle<Object> stack_trace, |
| 1098 | Handle<Object> stack_frames) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1099 | CALL_HEAP_FUNCTION(isolate(), |
| 1100 | isolate()->heap()->AllocateJSMessageObject(*type, |
| 1101 | *arguments, |
| 1102 | start_position, |
| 1103 | end_position, |
| 1104 | *script, |
| 1105 | *stack_trace, |
| 1106 | *stack_frames), |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1107 | JSMessageObject); |
| 1108 | } |
| 1109 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1110 | Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(Handle<String> name) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1111 | CALL_HEAP_FUNCTION(isolate(), |
| 1112 | isolate()->heap()->AllocateSharedFunctionInfo(*name), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1113 | SharedFunctionInfo); |
| 1114 | } |
| 1115 | |
| 1116 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1117 | Handle<String> Factory::NumberToString(Handle<Object> number) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1118 | CALL_HEAP_FUNCTION(isolate(), |
| 1119 | isolate()->heap()->NumberToString(*number), String); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1123 | Handle<String> Factory::Uint32ToString(uint32_t value) { |
| 1124 | CALL_HEAP_FUNCTION(isolate(), |
| 1125 | isolate()->heap()->Uint32ToString(value), String); |
| 1126 | } |
| 1127 | |
| 1128 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1129 | Handle<SeededNumberDictionary> Factory::DictionaryAtNumberPut( |
| 1130 | Handle<SeededNumberDictionary> dictionary, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1131 | uint32_t key, |
| 1132 | Handle<Object> value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1133 | CALL_HEAP_FUNCTION(isolate(), |
| 1134 | dictionary->AtNumberPut(key, *value), |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1135 | SeededNumberDictionary); |
| 1136 | } |
| 1137 | |
| 1138 | |
| 1139 | Handle<UnseededNumberDictionary> Factory::DictionaryAtNumberPut( |
| 1140 | Handle<UnseededNumberDictionary> dictionary, |
| 1141 | uint32_t key, |
| 1142 | Handle<Object> value) { |
| 1143 | CALL_HEAP_FUNCTION(isolate(), |
| 1144 | dictionary->AtNumberPut(key, *value), |
| 1145 | UnseededNumberDictionary); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | |
| 1149 | Handle<JSFunction> Factory::NewFunctionHelper(Handle<String> name, |
| 1150 | Handle<Object> prototype) { |
| 1151 | Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1152 | CALL_HEAP_FUNCTION( |
| 1153 | isolate(), |
| 1154 | isolate()->heap()->AllocateFunction(*isolate()->function_map(), |
| 1155 | *function_share, |
| 1156 | *prototype), |
| 1157 | JSFunction); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
| 1162 | Handle<Object> prototype) { |
| 1163 | Handle<JSFunction> fun = NewFunctionHelper(name, prototype); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1164 | fun->set_context(isolate()->context()->native_context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1165 | return fun; |
| 1166 | } |
| 1167 | |
| 1168 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1169 | Handle<JSFunction> Factory::NewFunctionWithoutPrototypeHelper( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1170 | Handle<String> name, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1171 | LanguageMode language_mode) { |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1172 | Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1173 | Handle<Map> map = (language_mode == CLASSIC_MODE) |
| 1174 | ? isolate()->function_without_prototype_map() |
| 1175 | : isolate()->strict_mode_function_without_prototype_map(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1176 | CALL_HEAP_FUNCTION(isolate(), |
| 1177 | isolate()->heap()->AllocateFunction( |
| 1178 | *map, |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1179 | *function_share, |
| 1180 | *the_hole_value()), |
| 1181 | JSFunction); |
| 1182 | } |
| 1183 | |
| 1184 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1185 | Handle<JSFunction> Factory::NewFunctionWithoutPrototype( |
| 1186 | Handle<String> name, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1187 | LanguageMode language_mode) { |
| 1188 | Handle<JSFunction> fun = |
| 1189 | NewFunctionWithoutPrototypeHelper(name, language_mode); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1190 | fun->set_context(isolate()->context()->native_context()); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1191 | return fun; |
| 1192 | } |
| 1193 | |
| 1194 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1195 | Handle<Object> Factory::ToObject(Handle<Object> object) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1196 | CALL_HEAP_FUNCTION(isolate(), object->ToObject(), Object); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1200 | Handle<Object> Factory::ToObject(Handle<Object> object, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1201 | Handle<Context> native_context) { |
| 1202 | CALL_HEAP_FUNCTION(isolate(), object->ToObject(*native_context), Object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1206 | #ifdef ENABLE_DEBUGGER_SUPPORT |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1207 | Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) { |
| 1208 | // Get the original code of the function. |
| 1209 | Handle<Code> code(shared->code()); |
| 1210 | |
| 1211 | // Create a copy of the code before allocating the debug info object to avoid |
| 1212 | // allocation while setting up the debug info object. |
| 1213 | Handle<Code> original_code(*Factory::CopyCode(code)); |
| 1214 | |
| 1215 | // Allocate initial fixed array for active break points before allocating the |
| 1216 | // debug info object to avoid allocation while setting up the debug info |
| 1217 | // object. |
| 1218 | Handle<FixedArray> break_points( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1219 | NewFixedArray(Debug::kEstimatedNofBreakPointsInFunction)); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1220 | |
| 1221 | // Create and set up the debug info object. Debug info contains function, a |
| 1222 | // copy of the original code, the executing code and initial fixed array for |
| 1223 | // active break points. |
| 1224 | Handle<DebugInfo> debug_info = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1225 | Handle<DebugInfo>::cast(NewStruct(DEBUG_INFO_TYPE)); |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1226 | debug_info->set_shared(*shared); |
| 1227 | debug_info->set_original_code(*original_code); |
| 1228 | debug_info->set_code(*code); |
| 1229 | debug_info->set_break_points(*break_points); |
| 1230 | |
| 1231 | // Link debug info to function. |
| 1232 | shared->set_debug_info(*debug_info); |
| 1233 | |
| 1234 | return debug_info; |
| 1235 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1236 | #endif |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 1237 | |
| 1238 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1239 | Handle<JSObject> Factory::NewArgumentsObject(Handle<Object> callee, |
| 1240 | int length) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1241 | CALL_HEAP_FUNCTION( |
| 1242 | isolate(), |
| 1243 | isolate()->heap()->AllocateArgumentsObject(*callee, length), JSObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | |
| 1247 | Handle<JSFunction> Factory::CreateApiFunction( |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1248 | Handle<FunctionTemplateInfo> obj, ApiInstanceType instance_type) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1249 | Handle<Code> code = isolate()->builtins()->HandleApiCall(); |
| 1250 | Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1251 | |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1252 | int internal_field_count = 0; |
| 1253 | if (!obj->instance_template()->IsUndefined()) { |
| 1254 | Handle<ObjectTemplateInfo> instance_template = |
| 1255 | Handle<ObjectTemplateInfo>( |
| 1256 | ObjectTemplateInfo::cast(obj->instance_template())); |
| 1257 | internal_field_count = |
| 1258 | Smi::cast(instance_template->internal_field_count())->value(); |
| 1259 | } |
| 1260 | |
| 1261 | int instance_size = kPointerSize * internal_field_count; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1262 | InstanceType type = INVALID_TYPE; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1263 | switch (instance_type) { |
| 1264 | case JavaScriptObject: |
| 1265 | type = JS_OBJECT_TYPE; |
| 1266 | instance_size += JSObject::kHeaderSize; |
| 1267 | break; |
| 1268 | case InnerGlobalObject: |
| 1269 | type = JS_GLOBAL_OBJECT_TYPE; |
| 1270 | instance_size += JSGlobalObject::kSize; |
| 1271 | break; |
| 1272 | case OuterGlobalObject: |
| 1273 | type = JS_GLOBAL_PROXY_TYPE; |
| 1274 | instance_size += JSGlobalProxy::kSize; |
| 1275 | break; |
| 1276 | default: |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1277 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1278 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1279 | ASSERT(type != INVALID_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1280 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1281 | Handle<JSFunction> result = |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1282 | NewFunction(Factory::empty_string(), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1283 | type, |
| 1284 | instance_size, |
| 1285 | code, |
| 1286 | true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1287 | |
| 1288 | // Set length. |
| 1289 | result->shared()->set_length(obj->length()); |
| 1290 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1291 | // Set class name. |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1292 | Handle<Object> class_name = Handle<Object>(obj->class_name(), isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1293 | if (class_name->IsString()) { |
| 1294 | result->shared()->set_instance_class_name(*class_name); |
| 1295 | result->shared()->set_name(*class_name); |
| 1296 | } |
| 1297 | |
| 1298 | Handle<Map> map = Handle<Map>(result->initial_map()); |
| 1299 | |
| 1300 | // Mark as undetectable if needed. |
| 1301 | if (obj->undetectable()) { |
| 1302 | map->set_is_undetectable(); |
| 1303 | } |
| 1304 | |
| 1305 | // Mark as hidden for the __proto__ accessor if needed. |
| 1306 | if (obj->hidden_prototype()) { |
| 1307 | map->set_is_hidden_prototype(); |
| 1308 | } |
| 1309 | |
| 1310 | // Mark as needs_access_check if needed. |
| 1311 | if (obj->needs_access_check()) { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1312 | map->set_is_access_check_needed(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1315 | // Set interceptor information in the map. |
| 1316 | if (!obj->named_property_handler()->IsUndefined()) { |
| 1317 | map->set_has_named_interceptor(); |
| 1318 | } |
| 1319 | if (!obj->indexed_property_handler()->IsUndefined()) { |
| 1320 | map->set_has_indexed_interceptor(); |
| 1321 | } |
| 1322 | |
| 1323 | // Set instance call-as-function information in the map. |
| 1324 | if (!obj->instance_call_handler()->IsUndefined()) { |
| 1325 | map->set_has_instance_call_handler(); |
| 1326 | } |
| 1327 | |
| 1328 | result->shared()->set_function_data(*obj); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1329 | result->shared()->set_construct_stub(*construct_stub); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1330 | result->shared()->DontAdaptArguments(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1331 | |
| 1332 | // Recursively copy parent templates' accessors, 'data' may be modified. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1333 | int max_number_of_additional_properties = 0; |
| 1334 | FunctionTemplateInfo* info = *obj; |
| 1335 | while (true) { |
| 1336 | Object* props = info->property_accessors(); |
| 1337 | if (!props->IsUndefined()) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1338 | Handle<Object> props_handle(props, isolate()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1339 | NeanderArray props_array(props_handle); |
| 1340 | max_number_of_additional_properties += props_array.length(); |
| 1341 | } |
| 1342 | Object* parent = info->parent_template(); |
| 1343 | if (parent->IsUndefined()) break; |
| 1344 | info = FunctionTemplateInfo::cast(parent); |
| 1345 | } |
| 1346 | |
| 1347 | Map::EnsureDescriptorSlack(map, max_number_of_additional_properties); |
| 1348 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1349 | while (true) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1350 | Handle<Object> props = Handle<Object>(obj->property_accessors(), |
| 1351 | isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1352 | if (!props->IsUndefined()) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1353 | Map::AppendCallbackDescriptors(map, props); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1354 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1355 | Handle<Object> parent = Handle<Object>(obj->parent_template(), isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1356 | if (parent->IsUndefined()) break; |
| 1357 | obj = Handle<FunctionTemplateInfo>::cast(parent); |
| 1358 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1359 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1360 | ASSERT(result->shared()->IsApiFunction()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1361 | return result; |
| 1362 | } |
| 1363 | |
| 1364 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1365 | Handle<MapCache> Factory::NewMapCache(int at_least_space_for) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1366 | CALL_HEAP_FUNCTION(isolate(), |
| 1367 | MapCache::Allocate(at_least_space_for), MapCache); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1371 | MUST_USE_RESULT static MaybeObject* UpdateMapCacheWith(Context* context, |
| 1372 | FixedArray* keys, |
| 1373 | Map* map) { |
| 1374 | Object* result; |
| 1375 | { MaybeObject* maybe_result = |
| 1376 | MapCache::cast(context->map_cache())->Put(keys, map); |
| 1377 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1378 | } |
| 1379 | context->set_map_cache(MapCache::cast(result)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1380 | return result; |
| 1381 | } |
| 1382 | |
| 1383 | |
| 1384 | Handle<MapCache> Factory::AddToMapCache(Handle<Context> context, |
| 1385 | Handle<FixedArray> keys, |
| 1386 | Handle<Map> map) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1387 | CALL_HEAP_FUNCTION(isolate(), |
| 1388 | UpdateMapCacheWith(*context, *keys, *map), MapCache); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | |
| 1392 | Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, |
| 1393 | Handle<FixedArray> keys) { |
| 1394 | if (context->map_cache()->IsUndefined()) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1395 | // Allocate the new map cache for the native context. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1396 | Handle<MapCache> new_cache = NewMapCache(24); |
| 1397 | context->set_map_cache(*new_cache); |
| 1398 | } |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1399 | // 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] | 1400 | Handle<MapCache> cache = |
| 1401 | Handle<MapCache>(MapCache::cast(context->map_cache())); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1402 | Handle<Object> result = Handle<Object>(cache->Lookup(*keys), isolate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1403 | if (result->IsMap()) return Handle<Map>::cast(result); |
| 1404 | // Create a new map and add it to the cache. |
| 1405 | Handle<Map> map = |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1406 | CopyMap(Handle<Map>(context->object_function()->initial_map()), |
| 1407 | keys->length()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1408 | AddToMapCache(context, keys, map); |
| 1409 | return Handle<Map>(map); |
| 1410 | } |
| 1411 | |
| 1412 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1413 | void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, |
| 1414 | JSRegExp::Type type, |
| 1415 | Handle<String> source, |
| 1416 | JSRegExp::Flags flags, |
| 1417 | Handle<Object> data) { |
| 1418 | Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize); |
| 1419 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1420 | store->set(JSRegExp::kTagIndex, Smi::FromInt(type)); |
| 1421 | store->set(JSRegExp::kSourceIndex, *source); |
| 1422 | store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value())); |
| 1423 | store->set(JSRegExp::kAtomPatternIndex, *data); |
| 1424 | regexp->set_data(*store); |
| 1425 | } |
| 1426 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1427 | void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp, |
| 1428 | JSRegExp::Type type, |
| 1429 | Handle<String> source, |
| 1430 | JSRegExp::Flags flags, |
| 1431 | int capture_count) { |
| 1432 | Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1433 | Smi* uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1434 | store->set(JSRegExp::kTagIndex, Smi::FromInt(type)); |
| 1435 | store->set(JSRegExp::kSourceIndex, *source); |
| 1436 | store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value())); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 1437 | store->set(JSRegExp::kIrregexpASCIICodeIndex, uninitialized); |
| 1438 | store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized); |
| 1439 | store->set(JSRegExp::kIrregexpASCIICodeSavedIndex, uninitialized); |
| 1440 | store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1441 | store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0)); |
| 1442 | store->set(JSRegExp::kIrregexpCaptureCountIndex, |
| 1443 | Smi::FromInt(capture_count)); |
| 1444 | regexp->set_data(*store); |
| 1445 | } |
| 1446 | |
| 1447 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1448 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1449 | void Factory::ConfigureInstance(Handle<FunctionTemplateInfo> desc, |
| 1450 | Handle<JSObject> instance, |
| 1451 | bool* pending_exception) { |
| 1452 | // Configure the instance by adding the properties specified by the |
| 1453 | // instance template. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1454 | Handle<Object> instance_template(desc->instance_template(), isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1455 | if (!instance_template->IsUndefined()) { |
| 1456 | Execution::ConfigureInstance(instance, |
| 1457 | instance_template, |
| 1458 | pending_exception); |
| 1459 | } else { |
| 1460 | *pending_exception = false; |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1465 | Handle<Object> Factory::GlobalConstantFor(Handle<String> name) { |
| 1466 | Heap* h = isolate()->heap(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1467 | if (name->Equals(h->undefined_string())) return undefined_value(); |
| 1468 | if (name->Equals(h->nan_string())) return nan_value(); |
| 1469 | if (name->Equals(h->infinity_string())) return infinity_value(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1470 | return Handle<Object>::null(); |
| 1471 | } |
| 1472 | |
| 1473 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1474 | Handle<Object> Factory::ToBoolean(bool value) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1475 | return value ? true_value() : false_value(); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1479 | } } // namespace v8::internal |