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