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