| 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. |
| 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 2140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3517 Handle<JSArray> last_match_array, | 3576 Handle<JSArray> last_match_array, |
| 3518 FixedArrayBuilder* builder) { | 3577 FixedArrayBuilder* builder) { |
| 3519 ASSERT(subject->IsFlat()); | 3578 ASSERT(subject->IsFlat()); |
| 3520 int match_start = -1; | 3579 int match_start = -1; |
| 3521 int match_end = 0; | 3580 int match_end = 0; |
| 3522 int pos = 0; | 3581 int pos = 0; |
| 3523 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); | 3582 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); |
| 3524 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION; | 3583 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION; |
| 3525 | 3584 |
| 3526 OffsetsVector registers(required_registers); | 3585 OffsetsVector registers(required_registers); |
| 3527 Vector<int> register_vector(registers.vector(), registers.length()); | 3586 Vector<int32_t> register_vector(registers.vector(), registers.length()); |
| 3528 int subject_length = subject->length(); | 3587 int subject_length = subject->length(); |
| 3529 | 3588 |
| 3530 for (;;) { // Break on failure, return on exception. | 3589 for (;;) { // Break on failure, return on exception. |
| 3531 RegExpImpl::IrregexpResult result = | 3590 RegExpImpl::IrregexpResult result = |
| 3532 RegExpImpl::IrregexpExecOnce(regexp, | 3591 RegExpImpl::IrregexpExecOnce(regexp, |
| 3533 subject, | 3592 subject, |
| 3534 pos, | 3593 pos, |
| 3535 register_vector); | 3594 register_vector); |
| 3536 if (result == RegExpImpl::RE_SUCCESS) { | 3595 if (result == RegExpImpl::RE_SUCCESS) { |
| 3537 match_start = register_vector[0]; | 3596 match_start = register_vector[0]; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3579 Handle<String> subject, | 3638 Handle<String> subject, |
| 3580 Handle<JSRegExp> regexp, | 3639 Handle<JSRegExp> regexp, |
| 3581 Handle<JSArray> last_match_array, | 3640 Handle<JSArray> last_match_array, |
| 3582 FixedArrayBuilder* builder) { | 3641 FixedArrayBuilder* builder) { |
| 3583 | 3642 |
| 3584 ASSERT(subject->IsFlat()); | 3643 ASSERT(subject->IsFlat()); |
| 3585 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); | 3644 int required_registers = RegExpImpl::IrregexpPrepare(regexp, subject); |
| 3586 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION; | 3645 if (required_registers < 0) return RegExpImpl::RE_EXCEPTION; |
| 3587 | 3646 |
| 3588 OffsetsVector registers(required_registers); | 3647 OffsetsVector registers(required_registers); |
| 3589 Vector<int> register_vector(registers.vector(), registers.length()); | 3648 Vector<int32_t> register_vector(registers.vector(), registers.length()); |
| 3590 | 3649 |
| 3591 RegExpImpl::IrregexpResult result = | 3650 RegExpImpl::IrregexpResult result = |
| 3592 RegExpImpl::IrregexpExecOnce(regexp, | 3651 RegExpImpl::IrregexpExecOnce(regexp, |
| 3593 subject, | 3652 subject, |
| 3594 0, | 3653 0, |
| 3595 register_vector); | 3654 register_vector); |
| 3596 | 3655 |
| 3597 int capture_count = regexp->CaptureCount(); | 3656 int capture_count = regexp->CaptureCount(); |
| 3598 int subject_length = subject->length(); | 3657 int subject_length = subject->length(); |
| 3599 | 3658 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3639 ASSERT(register_vector[i * 2 + 1] < 0); | 3698 ASSERT(register_vector[i * 2 + 1] < 0); |
| 3640 elements->set(i, Heap::undefined_value()); | 3699 elements->set(i, Heap::undefined_value()); |
| 3641 } | 3700 } |
| 3642 } | 3701 } |
| 3643 elements->set(capture_count + 1, Smi::FromInt(match_start)); | 3702 elements->set(capture_count + 1, Smi::FromInt(match_start)); |
| 3644 elements->set(capture_count + 2, *subject); | 3703 elements->set(capture_count + 2, *subject); |
| 3645 builder->Add(*Factory::NewJSArrayWithElements(elements)); | 3704 builder->Add(*Factory::NewJSArrayWithElements(elements)); |
| 3646 } | 3705 } |
| 3647 // Swap register vectors, so the last successful match is in | 3706 // Swap register vectors, so the last successful match is in |
| 3648 // prev_register_vector. | 3707 // prev_register_vector. |
| 3649 Vector<int> tmp = prev_register_vector; | 3708 Vector<int32_t> tmp = prev_register_vector; |
| 3650 prev_register_vector = register_vector; | 3709 prev_register_vector = register_vector; |
| 3651 register_vector = tmp; | 3710 register_vector = tmp; |
| 3652 | 3711 |
| 3653 if (match_end > match_start) { | 3712 if (match_end > match_start) { |
| 3654 pos = match_end; | 3713 pos = match_end; |
| 3655 } else { | 3714 } else { |
| 3656 pos = match_end + 1; | 3715 pos = match_end + 1; |
| 3657 if (pos > subject_length) { | 3716 if (pos > subject_length) { |
| 3658 break; | 3717 break; |
| 3659 } | 3718 } |
| (...skipping 6990 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 |