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