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