OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 int y = (t != NULL ? t->index() : 0); | 45 int y = (t != NULL ? t->index() : 0); |
46 // Consider sorting them according to type as well? | 46 // Consider sorting them according to type as well? |
47 return x - y; | 47 return x - y; |
48 } | 48 } |
49 | 49 |
50 | 50 |
51 template<class Allocator> | 51 template<class Allocator> |
52 ScopeInfo<Allocator>::ScopeInfo(Scope* scope) | 52 ScopeInfo<Allocator>::ScopeInfo(Scope* scope) |
53 : function_name_(FACTORY->empty_symbol()), | 53 : function_name_(FACTORY->empty_symbol()), |
54 calls_eval_(scope->calls_eval()), | 54 calls_eval_(scope->calls_eval()), |
| 55 is_strict_mode_(scope->is_strict_mode()), |
55 parameters_(scope->num_parameters()), | 56 parameters_(scope->num_parameters()), |
56 stack_slots_(scope->num_stack_slots()), | 57 stack_slots_(scope->num_stack_slots()), |
57 context_slots_(scope->num_heap_slots()), | 58 context_slots_(scope->num_heap_slots()), |
58 context_modes_(scope->num_heap_slots()) { | 59 context_modes_(scope->num_heap_slots()) { |
59 // Add parameters. | 60 // Add parameters. |
60 for (int i = 0; i < scope->num_parameters(); i++) { | 61 for (int i = 0; i < scope->num_parameters(); i++) { |
61 ASSERT(parameters_.length() == i); | 62 ASSERT(parameters_.length() == i); |
62 parameters_.Add(scope->parameter(i)->name()); | 63 parameters_.Add(scope->parameter(i)->name()); |
63 } | 64 } |
64 | 65 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 : function_name_(FACTORY->empty_symbol()), | 242 : function_name_(FACTORY->empty_symbol()), |
242 parameters_(4), | 243 parameters_(4), |
243 stack_slots_(8), | 244 stack_slots_(8), |
244 context_slots_(8), | 245 context_slots_(8), |
245 context_modes_(8) { | 246 context_modes_(8) { |
246 if (data->length() > 0) { | 247 if (data->length() > 0) { |
247 Object** p0 = data->data_start(); | 248 Object** p0 = data->data_start(); |
248 Object** p = p0; | 249 Object** p = p0; |
249 p = ReadSymbol(p, &function_name_); | 250 p = ReadSymbol(p, &function_name_); |
250 p = ReadBool(p, &calls_eval_); | 251 p = ReadBool(p, &calls_eval_); |
| 252 p = ReadBool(p, &is_strict_mode_); |
251 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); | 253 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); |
252 p = ReadList<Allocator>(p, ¶meters_); | 254 p = ReadList<Allocator>(p, ¶meters_); |
253 p = ReadList<Allocator>(p, &stack_slots_); | 255 p = ReadList<Allocator>(p, &stack_slots_); |
254 ASSERT((p - p0) == FixedArray::cast(data)->length()); | 256 ASSERT((p - p0) == FixedArray::cast(data)->length()); |
255 } | 257 } |
256 } | 258 } |
257 | 259 |
258 | 260 |
259 static inline Object** WriteInt(Object** p, int x) { | 261 static inline Object** WriteInt(Object** p, int x) { |
260 *p++ = Smi::FromInt(x); | 262 *p++ = Smi::FromInt(x); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 for (int i = 0; i < n; i++) { | 296 for (int i = 0; i < n; i++) { |
295 p = WriteSymbol(p, list->at(i)); | 297 p = WriteSymbol(p, list->at(i)); |
296 p = WriteInt(p, modes->at(i)); | 298 p = WriteInt(p, modes->at(i)); |
297 } | 299 } |
298 return p; | 300 return p; |
299 } | 301 } |
300 | 302 |
301 | 303 |
302 template<class Allocator> | 304 template<class Allocator> |
303 Handle<SerializedScopeInfo> ScopeInfo<Allocator>::Serialize() { | 305 Handle<SerializedScopeInfo> ScopeInfo<Allocator>::Serialize() { |
304 // function name, calls eval, length for 3 tables: | 306 // function name, calls eval, is_strict_mode, length for 3 tables: |
305 const int extra_slots = 1 + 1 + 3; | 307 const int extra_slots = 1 + 1 + 1 + 3; |
306 int length = extra_slots + | 308 int length = extra_slots + |
307 context_slots_.length() * 2 + | 309 context_slots_.length() * 2 + |
308 parameters_.length() + | 310 parameters_.length() + |
309 stack_slots_.length(); | 311 stack_slots_.length(); |
310 | 312 |
311 Handle<SerializedScopeInfo> data( | 313 Handle<SerializedScopeInfo> data( |
312 SerializedScopeInfo::cast(*FACTORY->NewFixedArray(length, TENURED))); | 314 SerializedScopeInfo::cast(*FACTORY->NewFixedArray(length, TENURED))); |
313 AssertNoAllocation nogc; | 315 AssertNoAllocation nogc; |
314 | 316 |
315 Object** p0 = data->data_start(); | 317 Object** p0 = data->data_start(); |
316 Object** p = p0; | 318 Object** p = p0; |
317 p = WriteSymbol(p, function_name_); | 319 p = WriteSymbol(p, function_name_); |
318 p = WriteBool(p, calls_eval_); | 320 p = WriteBool(p, calls_eval_); |
| 321 p = WriteBool(p, is_strict_mode_); |
319 p = WriteList(p, &context_slots_, &context_modes_); | 322 p = WriteList(p, &context_slots_, &context_modes_); |
320 p = WriteList(p, ¶meters_); | 323 p = WriteList(p, ¶meters_); |
321 p = WriteList(p, &stack_slots_); | 324 p = WriteList(p, &stack_slots_); |
322 ASSERT((p - p0) == length); | 325 ASSERT((p - p0) == length); |
323 | 326 |
324 return data; | 327 return data; |
325 } | 328 } |
326 | 329 |
327 | 330 |
328 template<class Allocator> | 331 template<class Allocator> |
(...skipping 27 matching lines...) Expand all Loading... |
356 } | 359 } |
357 | 360 |
358 | 361 |
359 SerializedScopeInfo* SerializedScopeInfo::Empty() { | 362 SerializedScopeInfo* SerializedScopeInfo::Empty() { |
360 return reinterpret_cast<SerializedScopeInfo*>(HEAP->empty_fixed_array()); | 363 return reinterpret_cast<SerializedScopeInfo*>(HEAP->empty_fixed_array()); |
361 } | 364 } |
362 | 365 |
363 | 366 |
364 Object** SerializedScopeInfo::ContextEntriesAddr() { | 367 Object** SerializedScopeInfo::ContextEntriesAddr() { |
365 ASSERT(length() > 0); | 368 ASSERT(length() > 0); |
366 return data_start() + 2; // +2 for function name and calls eval. | 369 // +3 for function name, calls eval, strict mode. |
| 370 return data_start() + 3; |
367 } | 371 } |
368 | 372 |
369 | 373 |
370 Object** SerializedScopeInfo::ParameterEntriesAddr() { | 374 Object** SerializedScopeInfo::ParameterEntriesAddr() { |
371 ASSERT(length() > 0); | 375 ASSERT(length() > 0); |
372 Object** p = ContextEntriesAddr(); | 376 Object** p = ContextEntriesAddr(); |
373 int number_of_context_slots; | 377 int number_of_context_slots; |
374 p = ReadInt(p, &number_of_context_slots); | 378 p = ReadInt(p, &number_of_context_slots); |
375 return p + number_of_context_slots*2; // *2 for pairs | 379 return p + number_of_context_slots*2; // *2 for pairs |
376 } | 380 } |
377 | 381 |
378 | 382 |
379 Object** SerializedScopeInfo::StackSlotEntriesAddr() { | 383 Object** SerializedScopeInfo::StackSlotEntriesAddr() { |
380 ASSERT(length() > 0); | 384 ASSERT(length() > 0); |
381 Object** p = ParameterEntriesAddr(); | 385 Object** p = ParameterEntriesAddr(); |
382 int number_of_parameter_slots; | 386 int number_of_parameter_slots; |
383 p = ReadInt(p, &number_of_parameter_slots); | 387 p = ReadInt(p, &number_of_parameter_slots); |
384 return p + number_of_parameter_slots; | 388 return p + number_of_parameter_slots; |
385 } | 389 } |
386 | 390 |
387 | 391 |
388 bool SerializedScopeInfo::CallsEval() { | 392 bool SerializedScopeInfo::CallsEval() { |
389 if (length() > 0) { | 393 if (length() > 0) { |
390 Object** p = data_start() + 1; // +1 for function name. | 394 Object** p = data_start() + 1; // +1 for function name. |
391 bool calls_eval; | 395 bool calls_eval; |
392 p = ReadBool(p, &calls_eval); | 396 p = ReadBool(p, &calls_eval); |
393 return calls_eval; | 397 return calls_eval; |
394 } | 398 } |
395 return true; | 399 return false; |
396 } | 400 } |
397 | 401 |
398 | 402 |
| 403 bool SerializedScopeInfo::IsStrictMode() { |
| 404 if (length() > 0) { |
| 405 Object** p = data_start() + 2; // +2 for function name, calls eval. |
| 406 bool strict_mode; |
| 407 p = ReadBool(p, &strict_mode); |
| 408 return strict_mode; |
| 409 } |
| 410 return false; |
| 411 } |
| 412 |
| 413 |
399 int SerializedScopeInfo::NumberOfStackSlots() { | 414 int SerializedScopeInfo::NumberOfStackSlots() { |
400 if (length() > 0) { | 415 if (length() > 0) { |
401 Object** p = StackSlotEntriesAddr(); | 416 Object** p = StackSlotEntriesAddr(); |
402 int number_of_stack_slots; | 417 int number_of_stack_slots; |
403 ReadInt(p, &number_of_stack_slots); | 418 ReadInt(p, &number_of_stack_slots); |
404 return number_of_stack_slots; | 419 return number_of_stack_slots; |
405 } | 420 } |
406 return 0; | 421 return 0; |
407 } | 422 } |
408 | 423 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 } | 637 } |
623 #endif // DEBUG | 638 #endif // DEBUG |
624 | 639 |
625 | 640 |
626 // Make sure the classes get instantiated by the template system. | 641 // Make sure the classes get instantiated by the template system. |
627 template class ScopeInfo<FreeStoreAllocationPolicy>; | 642 template class ScopeInfo<FreeStoreAllocationPolicy>; |
628 template class ScopeInfo<PreallocatedStorage>; | 643 template class ScopeInfo<PreallocatedStorage>; |
629 template class ScopeInfo<ZoneListAllocationPolicy>; | 644 template class ScopeInfo<ZoneListAllocationPolicy>; |
630 | 645 |
631 } } // namespace v8::internal | 646 } } // namespace v8::internal |
OLD | NEW |