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 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1357 array->set_properties(Heap::empty_fixed_array()); | 1357 array->set_properties(Heap::empty_fixed_array()); |
1358 array->set_elements(elements); | 1358 array->set_elements(elements); |
1359 array->set_length(Smi::FromInt(elements_count)); | 1359 array->set_length(Smi::FromInt(elements_count)); |
1360 // Write in-object properties after the length of the array. | 1360 // Write in-object properties after the length of the array. |
1361 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]); | 1361 array->InObjectPropertyAtPut(JSRegExpResult::kIndexIndex, args[1]); |
1362 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]); | 1362 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, args[2]); |
1363 return array; | 1363 return array; |
1364 } | 1364 } |
1365 | 1365 |
1366 | 1366 |
1367 static Object* Runtime_RegExpCloneResult(Arguments args) { | |
1368 ASSERT(args.length() == 1); | |
1369 Map* regexp_result_map; | |
1370 { | |
1371 AssertNoAllocation no_gc; | |
1372 HandleScope handles; | |
1373 regexp_result_map = Top::global_context()->regexp_result_map(); | |
1374 } | |
1375 if (!args[0]->IsJSArray()) return args[0]; | |
1376 | |
1377 JSArray* result = JSArray::cast(args[0]); | |
1378 // Arguments to RegExpCloneResult should always be fresh RegExp exec call | |
1379 // results (either a fresh JSRegExpResult or null). | |
1380 // If the argument is not a JSRegExpResult, or isn't unmodified, just return | |
1381 // the argument uncloned. | |
1382 if (result->map() != regexp_result_map) return result; | |
1383 | |
1384 // Having the original JSRegExpResult map guarantees that we have | |
1385 // fast elements and no properties except the two in-object properties. | |
1386 ASSERT(result->HasFastElements()); | |
1387 ASSERT(result->properties() == Heap::empty_fixed_array()); | |
1388 ASSERT_EQ(2, regexp_result_map->inobject_properties()); | |
1389 | |
1390 Object* new_array_alloc = Heap::AllocateRaw(JSRegExpResult::kSize, | |
1391 NEW_SPACE, | |
1392 OLD_POINTER_SPACE); | |
1393 if (new_array_alloc->IsFailure()) return new_array_alloc; | |
1394 | |
1395 // Set HeapObject map to JSRegExpResult map. | |
1396 reinterpret_cast<HeapObject*>(new_array_alloc)->set_map(regexp_result_map); | |
1397 | |
1398 JSArray* new_array = JSArray::cast(new_array_alloc); | |
1399 | |
1400 // Copy JSObject properties. | |
1401 new_array->set_properties(result->properties()); // Empty FixedArray. | |
1402 | |
1403 // Copy JSObject elements as copy-on-write. | |
1404 FixedArray* elements = FixedArray::cast(result->elements()); | |
1405 if (elements != Heap::empty_fixed_array()) { | |
1406 ASSERT(!Heap::InNewSpace(Heap::fixed_cow_array_map())); | |
1407 // No write barrier is necessary when writing old-space pointer. | |
Vitaly Repeshko
2010/08/20 13:29:49
I don't think we need to have this comment or asse
Lasse Reichstein
2010/08/23 12:52:11
True, maps are all in Map-space.
| |
1408 elements->set_map(Heap::fixed_cow_array_map()); | |
1409 } | |
1410 new_array->set_elements(elements); | |
1411 | |
1412 // Copy JSArray length. | |
1413 new_array->set_length(result->length()); | |
1414 | |
1415 // Copy JSRegExpResult in-object property fields input and index. | |
1416 new_array->FastPropertyAtPut(JSRegExpResult::kIndexIndex, | |
1417 result->FastPropertyAt( | |
1418 JSRegExpResult::kIndexIndex)); | |
1419 new_array->FastPropertyAtPut(JSRegExpResult::kInputIndex, | |
1420 result->FastPropertyAt( | |
1421 JSRegExpResult::kInputIndex)); | |
1422 return new_array; | |
1423 } | |
1424 | |
1425 | |
1367 static Object* Runtime_RegExpInitializeObject(Arguments args) { | 1426 static Object* Runtime_RegExpInitializeObject(Arguments args) { |
1368 AssertNoAllocation no_alloc; | 1427 AssertNoAllocation no_alloc; |
1369 ASSERT(args.length() == 5); | 1428 ASSERT(args.length() == 5); |
1370 CONVERT_CHECKED(JSRegExp, regexp, args[0]); | 1429 CONVERT_CHECKED(JSRegExp, regexp, args[0]); |
1371 CONVERT_CHECKED(String, source, args[1]); | 1430 CONVERT_CHECKED(String, source, args[1]); |
1372 | 1431 |
1373 Object* global = args[2]; | 1432 Object* global = args[2]; |
1374 if (!global->IsTrue()) global = Heap::false_value(); | 1433 if (!global->IsTrue()) global = Heap::false_value(); |
1375 | 1434 |
1376 Object* ignoreCase = args[3]; | 1435 Object* ignoreCase = args[3]; |
(...skipping 9273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10650 } else { | 10709 } else { |
10651 // Handle last resort GC and make sure to allow future allocations | 10710 // Handle last resort GC and make sure to allow future allocations |
10652 // to grow the heap without causing GCs (if possible). | 10711 // to grow the heap without causing GCs (if possible). |
10653 Counters::gc_last_resort_from_js.Increment(); | 10712 Counters::gc_last_resort_from_js.Increment(); |
10654 Heap::CollectAllGarbage(false); | 10713 Heap::CollectAllGarbage(false); |
10655 } | 10714 } |
10656 } | 10715 } |
10657 | 10716 |
10658 | 10717 |
10659 } } // namespace v8::internal | 10718 } } // namespace v8::internal |
OLD | NEW |