Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/jsregexp.cc

Issue 2858033: Fix Chromium issue 47824. (Closed)
Patch Set: Addressed review comments Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/handles.cc ('k') | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 flags, 349 flags,
350 capture_count); 350 capture_count);
351 } 351 }
352 352
353 353
354 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, 354 int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp,
355 Handle<String> subject) { 355 Handle<String> subject) {
356 if (!subject->IsFlat()) { 356 if (!subject->IsFlat()) {
357 FlattenString(subject); 357 FlattenString(subject);
358 } 358 }
359 bool is_ascii = subject->IsAsciiRepresentation(); 359 // Check the asciiness of the underlying storage.
360 bool is_ascii;
361 {
362 AssertNoAllocation no_gc;
363 String* sequential_string = *subject;
364 if (subject->IsConsString()) {
365 sequential_string = ConsString::cast(*subject)->first();
366 }
367 is_ascii = sequential_string->IsAsciiRepresentation();
368 }
360 if (!EnsureCompiledIrregexp(regexp, is_ascii)) { 369 if (!EnsureCompiledIrregexp(regexp, is_ascii)) {
361 return -1; 370 return -1;
362 } 371 }
363 #ifdef V8_INTERPRETED_REGEXP 372 #ifdef V8_INTERPRETED_REGEXP
364 // Byte-code regexp needs space allocated for all its registers. 373 // Byte-code regexp needs space allocated for all its registers.
365 return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data())); 374 return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data()));
366 #else // V8_INTERPRETED_REGEXP 375 #else // V8_INTERPRETED_REGEXP
367 // Native regexp only needs room to output captures. Registers are handled 376 // Native regexp only needs room to output captures. Registers are handled
368 // internally. 377 // internally.
369 return (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2; 378 return (IrregexpNumberOfCaptures(FixedArray::cast(regexp->data())) + 1) * 2;
370 #endif // V8_INTERPRETED_REGEXP 379 #endif // V8_INTERPRETED_REGEXP
371 } 380 }
372 381
373 382
374 RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce(Handle<JSRegExp> regexp, 383 RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce(Handle<JSRegExp> regexp,
375 Handle<String> subject, 384 Handle<String> subject,
376 int index, 385 int index,
377 Vector<int> output) { 386 Vector<int> output) {
378 Handle<FixedArray> irregexp(FixedArray::cast(regexp->data())); 387 Handle<FixedArray> irregexp(FixedArray::cast(regexp->data()));
379 388
380 ASSERT(index >= 0); 389 ASSERT(index >= 0);
381 ASSERT(index <= subject->length()); 390 ASSERT(index <= subject->length());
382 ASSERT(subject->IsFlat()); 391 ASSERT(subject->IsFlat());
383 392
393 // A flat ASCII string might have a two-byte first part.
394 if (subject->IsConsString()) {
395 subject = Handle<String>(ConsString::cast(*subject)->first());
396 }
397
384 #ifndef V8_INTERPRETED_REGEXP 398 #ifndef V8_INTERPRETED_REGEXP
385 ASSERT(output.length() >= 399 ASSERT(output.length() >=
386 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); 400 (IrregexpNumberOfCaptures(*irregexp) + 1) * 2);
387 do { 401 do {
388 bool is_ascii = subject->IsAsciiRepresentation(); 402 bool is_ascii = subject->IsAsciiRepresentation();
389 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii)); 403 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii));
390 NativeRegExpMacroAssembler::Result res = 404 NativeRegExpMacroAssembler::Result res =
391 NativeRegExpMacroAssembler::Match(code, 405 NativeRegExpMacroAssembler::Match(code,
392 subject, 406 subject,
393 output.start(), 407 output.start(),
394 output.length(), 408 output.length(),
395 index); 409 index);
396 if (res != NativeRegExpMacroAssembler::RETRY) { 410 if (res != NativeRegExpMacroAssembler::RETRY) {
397 ASSERT(res != NativeRegExpMacroAssembler::EXCEPTION || 411 ASSERT(res != NativeRegExpMacroAssembler::EXCEPTION ||
398 Top::has_pending_exception()); 412 Top::has_pending_exception());
399 STATIC_ASSERT( 413 STATIC_ASSERT(
400 static_cast<int>(NativeRegExpMacroAssembler::SUCCESS) == RE_SUCCESS); 414 static_cast<int>(NativeRegExpMacroAssembler::SUCCESS) == RE_SUCCESS);
401 STATIC_ASSERT( 415 STATIC_ASSERT(
402 static_cast<int>(NativeRegExpMacroAssembler::FAILURE) == RE_FAILURE); 416 static_cast<int>(NativeRegExpMacroAssembler::FAILURE) == RE_FAILURE);
403 STATIC_ASSERT(static_cast<int>(NativeRegExpMacroAssembler::EXCEPTION) 417 STATIC_ASSERT(static_cast<int>(NativeRegExpMacroAssembler::EXCEPTION)
404 == RE_EXCEPTION); 418 == RE_EXCEPTION);
405 return static_cast<IrregexpResult>(res); 419 return static_cast<IrregexpResult>(res);
406 } 420 }
407 // If result is RETRY, the string has changed representation, and we 421 // If result is RETRY, the string has changed representation, and we
408 // must restart from scratch. 422 // must restart from scratch.
409 // In this case, it means we must make sure we are prepared to handle 423 // In this case, it means we must make sure we are prepared to handle
410 // the, potentially, differen subject (the string can switch between 424 // the, potentially, different subject (the string can switch between
411 // being internal and external, and even between being ASCII and UC16, 425 // being internal and external, and even between being ASCII and UC16,
412 // but the characters are always the same). 426 // but the characters are always the same).
413 IrregexpPrepare(regexp, subject); 427 IrregexpPrepare(regexp, subject);
414 } while (true); 428 } while (true);
415 UNREACHABLE(); 429 UNREACHABLE();
416 return RE_EXCEPTION; 430 return RE_EXCEPTION;
417 #else // V8_INTERPRETED_REGEXP 431 #else // V8_INTERPRETED_REGEXP
418 432
419 ASSERT(output.length() >= IrregexpNumberOfRegisters(*irregexp)); 433 ASSERT(output.length() >= IrregexpNumberOfRegisters(*irregexp));
420 bool is_ascii = subject->IsAsciiRepresentation(); 434 bool is_ascii = subject->IsAsciiRepresentation();
(...skipping 4839 matching lines...) Expand 10 before | Expand all | Expand 10 after
5260 node, 5274 node,
5261 data->capture_count, 5275 data->capture_count,
5262 pattern); 5276 pattern);
5263 } 5277 }
5264 5278
5265 5279
5266 int OffsetsVector::static_offsets_vector_[ 5280 int OffsetsVector::static_offsets_vector_[
5267 OffsetsVector::kStaticOffsetsVectorSize]; 5281 OffsetsVector::kStaticOffsetsVectorSize];
5268 5282
5269 }} // namespace v8::internal 5283 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « src/handles.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698