OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 uint32_t start_index; | 215 uint32_t start_index; |
216 if (!Array::IndexFromObject(*index, &start_index)) { | 216 if (!Array::IndexFromObject(*index, &start_index)) { |
217 return Handle<Smi>(Smi::FromInt(-1)); | 217 return Handle<Smi>(Smi::FromInt(-1)); |
218 } | 218 } |
219 | 219 |
220 LOG(RegExpExecEvent(re, start_index, subject)); | 220 LOG(RegExpExecEvent(re, start_index, subject)); |
221 int value = Runtime::StringMatch(subject, needle, start_index); | 221 int value = Runtime::StringMatch(subject, needle, start_index); |
222 if (value == -1) return Factory::null_value(); | 222 if (value == -1) return Factory::null_value(); |
223 | 223 |
224 Handle<FixedArray> array = Factory::NewFixedArray(2); | 224 Handle<FixedArray> array = Factory::NewFixedArray(2); |
225 array->set(0, Smi::FromInt(value)); | 225 array->set(0, |
226 array->set(1, Smi::FromInt(value + needle->length())); | 226 Smi::FromInt(value), |
| 227 SKIP_WRITE_BARRIER); |
| 228 array->set(1, |
| 229 Smi::FromInt(value + needle->length()), |
| 230 SKIP_WRITE_BARRIER); |
227 return Factory::NewJSArrayWithElements(array); | 231 return Factory::NewJSArrayWithElements(array); |
228 } | 232 } |
229 | 233 |
230 | 234 |
231 Handle<Object> RegExpImpl::AtomExecGlobal(Handle<JSRegExp> re, | 235 Handle<Object> RegExpImpl::AtomExecGlobal(Handle<JSRegExp> re, |
232 Handle<String> subject) { | 236 Handle<String> subject) { |
233 Handle<String> needle(String::cast(re->data())); | 237 Handle<String> needle(String::cast(re->data())); |
234 Handle<JSArray> result = Factory::NewJSArray(1); | 238 Handle<JSArray> result = Factory::NewJSArray(1); |
235 int index = 0; | 239 int index = 0; |
236 int match_count = 0; | 240 int match_count = 0; |
237 int subject_length = subject->length(); | 241 int subject_length = subject->length(); |
238 int needle_length = needle->length(); | 242 int needle_length = needle->length(); |
239 while (true) { | 243 while (true) { |
240 LOG(RegExpExecEvent(re, index, subject)); | 244 LOG(RegExpExecEvent(re, index, subject)); |
241 int value = -1; | 245 int value = -1; |
242 if (index + needle_length <= subject_length) { | 246 if (index + needle_length <= subject_length) { |
243 value = Runtime::StringMatch(subject, needle, index); | 247 value = Runtime::StringMatch(subject, needle, index); |
244 } | 248 } |
245 if (value == -1) break; | 249 if (value == -1) break; |
246 HandleScope scope; | 250 HandleScope scope; |
247 int end = value + needle_length; | 251 int end = value + needle_length; |
248 | 252 |
249 Handle<FixedArray> array = Factory::NewFixedArray(2); | 253 Handle<FixedArray> array = Factory::NewFixedArray(2); |
250 array->set(0, Smi::FromInt(value)); | 254 array->set(0, |
251 array->set(1, Smi::FromInt(end)); | 255 Smi::FromInt(value), |
| 256 SKIP_WRITE_BARRIER); |
| 257 array->set(1, |
| 258 Smi::FromInt(end), |
| 259 SKIP_WRITE_BARRIER); |
252 Handle<JSArray> pair = Factory::NewJSArrayWithElements(array); | 260 Handle<JSArray> pair = Factory::NewJSArrayWithElements(array); |
253 SetElement(result, match_count, pair); | 261 SetElement(result, match_count, pair); |
254 match_count++; | 262 match_count++; |
255 index = end; | 263 index = end; |
256 if (needle_length == 0) index++; | 264 if (needle_length == 0) index++; |
257 } | 265 } |
258 return result; | 266 return result; |
259 } | 267 } |
260 | 268 |
261 | 269 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 Handle<Object> code(Smi::FromInt(rc)); | 373 Handle<Object> code(Smi::FromInt(rc)); |
366 Handle<Object> args[2] = { Factory::LookupAsciiSymbol("jsre_exec"), code }; | 374 Handle<Object> args[2] = { Factory::LookupAsciiSymbol("jsre_exec"), code }; |
367 Handle<Object> regexp_err( | 375 Handle<Object> regexp_err( |
368 Factory::NewTypeError("jsre_error", HandleVector(args, 2))); | 376 Factory::NewTypeError("jsre_error", HandleVector(args, 2))); |
369 return Handle<Object>(Top::Throw(*regexp_err)); | 377 return Handle<Object>(Top::Throw(*regexp_err)); |
370 } | 378 } |
371 | 379 |
372 Handle<FixedArray> array = Factory::NewFixedArray(2 * (num_captures+1)); | 380 Handle<FixedArray> array = Factory::NewFixedArray(2 * (num_captures+1)); |
373 // The captures come in (start, end+1) pairs. | 381 // The captures come in (start, end+1) pairs. |
374 for (int i = 0; i < 2 * (num_captures+1); i += 2) { | 382 for (int i = 0; i < 2 * (num_captures+1); i += 2) { |
375 array->set(i, Smi::FromInt(offsets_vector[i])); | 383 array->set(i, |
376 array->set(i+1, Smi::FromInt(offsets_vector[i+1])); | 384 Smi::FromInt(offsets_vector[i]), |
| 385 SKIP_WRITE_BARRIER); |
| 386 array->set(i+1, |
| 387 Smi::FromInt(offsets_vector[i+1]), |
| 388 SKIP_WRITE_BARRIER); |
377 } | 389 } |
378 return Factory::NewJSArrayWithElements(array); | 390 return Factory::NewJSArrayWithElements(array); |
379 } | 391 } |
380 | 392 |
381 | 393 |
382 class OffsetsVector { | 394 class OffsetsVector { |
383 public: | 395 public: |
384 inline OffsetsVector(int num_captures) { | 396 inline OffsetsVector(int num_captures) { |
385 offsets_vector_length_ = (num_captures + 1) * 3; | 397 offsets_vector_length_ = (num_captures + 1) * 3; |
386 if (offsets_vector_length_ > kStaticOffsetsVectorSize) { | 398 if (offsets_vector_length_ > kStaticOffsetsVectorSize) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 } | 505 } |
494 | 506 |
495 | 507 |
496 ByteArray* RegExpImpl::JsreInternal(Handle<JSRegExp> re) { | 508 ByteArray* RegExpImpl::JsreInternal(Handle<JSRegExp> re) { |
497 Object* value = re->data(); | 509 Object* value = re->data(); |
498 ASSERT(value->IsFixedArray()); | 510 ASSERT(value->IsFixedArray()); |
499 return ByteArray::cast(FixedArray::cast(value)->get(INTERNAL_INDEX)); | 511 return ByteArray::cast(FixedArray::cast(value)->get(INTERNAL_INDEX)); |
500 } | 512 } |
501 | 513 |
502 }} // namespace v8::internal | 514 }} // namespace v8::internal |
OLD | NEW |