OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 |
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1417 array->set_properties(Heap::empty_fixed_array()); | 1417 array->set_properties(Heap::empty_fixed_array()); |
1418 array->set_elements(elements); | 1418 array->set_elements(elements); |
1419 array->set_length(Smi::FromInt(elements_count)); | 1419 array->set_length(Smi::FromInt(elements_count)); |
1420 // Write in-object properties after the length of the array. | 1420 // Write in-object properties after the length of the array. |
1421 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]); | 1421 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]); |
1422 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]); | 1422 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]); |
1423 return array; | 1423 return array; |
1424 } | 1424 } |
1425 | 1425 |
1426 | 1426 |
1427 static MaybeObject* Runtime_RegExpCloneResult(Arguments args) { | |
1428 ASSERT(args.length() == 1); | |
1429 Map* regexp_result_map; | |
1430 { | |
1431 AssertNoAllocation no_gc; | |
1432 HandleScope handles; | |
1433 regexp_result_map = Top::global_context()->regexp_result_map(); | |
1434 } | |
1435 if (!args[0]->IsJSArray()) return args[0]; | |
1436 | |
1437 JSArray* result = JSArray::cast(args[0]); | |
1438 // Arguments to RegExpCloneResult should always be fresh RegExp exec call | |
1439 // results (either a fresh JSRegExpResult or null). | |
1440 // If the argument is not a JSRegExpResult, or isn't unmodified, just return | |
1441 // the argument uncloned. | |
1442 if (result->map() != regexp_result_map) return result; | |
1443 | |
1444 // Having the original JSRegExpResult map guarantees that we have | |
1445 // fast elements and no properties except the two in-object properties. | |
1446 ASSERT(result->HasFastElements()); | |
1447 ASSERT(result->properties() == Heap::empty_fixed_array()); | |
1448 ASSERT_EQ(2, regexp_result_map->inobject_properties()); | |
1449 | |
1450 Object* new_array_alloc; | |
1451 { MaybeObject* maybe_new_array_alloc = | |
1452 Heap::AllocateRaw(JSRegExpResult::kSize, NEW_SPACE, OLD_POINTER_SPACE); | |
1453 if (!maybe_new_array_alloc->ToObject(&new_array_alloc)) { | |
1454 return maybe_new_array_alloc; | |
1455 } | |
1456 } | |
1457 | |
1458 // Set HeapObject map to JSRegExpResult map. | |
1459 reinterpret_cast<HeapObject*>(new_array_alloc)->set_map(regexp_result_map); | |
1460 | |
1461 JSArray* new_array = JSArray::cast(new_array_alloc); | |
1462 | |
1463 // Copy JSObject properties. | |
1464 new_array->set_properties(result->properties()); // Empty FixedArray. | |
1465 | |
1466 // Copy JSObject elements as copy-on-write. | |
1467 FixedArray* elements = FixedArray::cast(result->elements()); | |
1468 if (elements != Heap::empty_fixed_array()) { | |
1469 elements->set_map(Heap::fixed_cow_array_map()); | |
1470 } | |
1471 new_array->set_elements(elements); | |
1472 | |
1473 // Copy JSArray length. | |
1474 new_array->set_length(result->length()); | |
1475 | |
1476 // Copy JSRegExpResult in-object property fields input and index. | |
1477 new_array->FastPropertyAtPut(JSRegExpResult::kIndexIndex, | |
1478 result->FastPropertyAt( | |
1479 JSRegExpResult::kIndexIndex)); | |
1480 new_array->FastPropertyAtPut(JSRegExpResult::kInputIndex, | |
1481 result->FastPropertyAt( | |
1482 JSRegExpResult::kInputIndex)); | |
1483 return new_array; | |
1484 } | |
1485 | |
1486 | |
1487 static MaybeObject* Runtime_RegExpInitializeObject(Arguments args) { | 1427 static MaybeObject* Runtime_RegExpInitializeObject(Arguments args) { |
1488 AssertNoAllocation no_alloc; | 1428 AssertNoAllocation no_alloc; |
1489 ASSERT(args.length() == 5); | 1429 ASSERT(args.length() == 5); |
1490 CONVERT_CHECKED(JSRegExp, regexp, args[0]); | 1430 CONVERT_CHECKED(JSRegExp, regexp, args[0]); |
1491 CONVERT_CHECKED(String, source, args[1]); | 1431 CONVERT_CHECKED(String, source, args[1]); |
1492 | 1432 |
1493 Object* global = args[2]; | 1433 Object* global = args[2]; |
1494 if (!global->IsTrue()) global = Heap::false_value(); | 1434 if (!global->IsTrue()) global = Heap::false_value(); |
1495 | 1435 |
1496 Object* ignoreCase = args[3]; | 1436 Object* ignoreCase = args[3]; |
(...skipping 8889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10386 } else { | 10326 } else { |
10387 // Handle last resort GC and make sure to allow future allocations | 10327 // Handle last resort GC and make sure to allow future allocations |
10388 // to grow the heap without causing GCs (if possible). | 10328 // to grow the heap without causing GCs (if possible). |
10389 Counters::gc_last_resort_from_js.Increment(); | 10329 Counters::gc_last_resort_from_js.Increment(); |
10390 Heap::CollectAllGarbage(false); | 10330 Heap::CollectAllGarbage(false); |
10391 } | 10331 } |
10392 } | 10332 } |
10393 | 10333 |
10394 | 10334 |
10395 } } // namespace v8::internal | 10335 } } // namespace v8::internal |
OLD | NEW |