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

Side by Side Diff: src/regexp/jsregexp.cc

Issue 2050343002: [regexp] Experimental support for regexp named captures (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: static_cast<int> Created 4 years, 6 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/regexp/jsregexp.h" 5 #include "src/regexp/jsregexp.h"
6 6
7 #include "src/ast/ast.h" 7 #include "src/ast/ast.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/compilation-cache.h" 9 #include "src/compilation-cache.h"
10 #include "src/compiler.h" 10 #include "src/compiler.h"
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 if (result.error_message != NULL) { 390 if (result.error_message != NULL) {
391 // Unable to compile regexp. 391 // Unable to compile regexp.
392 Handle<String> error_message = isolate->factory()->NewStringFromUtf8( 392 Handle<String> error_message = isolate->factory()->NewStringFromUtf8(
393 CStrVector(result.error_message)).ToHandleChecked(); 393 CStrVector(result.error_message)).ToHandleChecked();
394 ThrowRegExpException(re, error_message); 394 ThrowRegExpException(re, error_message);
395 return false; 395 return false;
396 } 396 }
397 397
398 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data())); 398 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data()));
399 data->set(JSRegExp::code_index(is_one_byte), result.code); 399 data->set(JSRegExp::code_index(is_one_byte), result.code);
400 SetIrregexpCaptureNameMap(*data, compile_data.capture_name_map);
400 int register_max = IrregexpMaxRegisterCount(*data); 401 int register_max = IrregexpMaxRegisterCount(*data);
401 if (result.num_registers > register_max) { 402 if (result.num_registers > register_max) {
402 SetIrregexpMaxRegisterCount(*data, result.num_registers); 403 SetIrregexpMaxRegisterCount(*data, result.num_registers);
403 } 404 }
404 405
405 return true; 406 return true;
406 } 407 }
407 408
408 409
409 int RegExpImpl::IrregexpMaxRegisterCount(FixedArray* re) { 410 int RegExpImpl::IrregexpMaxRegisterCount(FixedArray* re) {
410 return Smi::cast( 411 return Smi::cast(
411 re->get(JSRegExp::kIrregexpMaxRegisterCountIndex))->value(); 412 re->get(JSRegExp::kIrregexpMaxRegisterCountIndex))->value();
412 } 413 }
413 414
414 415
415 void RegExpImpl::SetIrregexpMaxRegisterCount(FixedArray* re, int value) { 416 void RegExpImpl::SetIrregexpMaxRegisterCount(FixedArray* re, int value) {
416 re->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(value)); 417 re->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(value));
417 } 418 }
418 419
420 void RegExpImpl::SetIrregexpCaptureNameMap(FixedArray* re,
421 Handle<FixedArray> value) {
422 re->set(JSRegExp::kIrregexpCaptureNameMapIndex,
423 value.is_null() ? nullptr : *value);
Yang 2016/06/13 10:54:52 let's store undefined or Smi::FromInt(0) instead.
jgruber 2016/06/13 13:09:59 Done.
424 }
419 425
420 int RegExpImpl::IrregexpNumberOfCaptures(FixedArray* re) { 426 int RegExpImpl::IrregexpNumberOfCaptures(FixedArray* re) {
421 return Smi::cast(re->get(JSRegExp::kIrregexpCaptureCountIndex))->value(); 427 return Smi::cast(re->get(JSRegExp::kIrregexpCaptureCountIndex))->value();
422 } 428 }
423 429
424 430
425 int RegExpImpl::IrregexpNumberOfRegisters(FixedArray* re) { 431 int RegExpImpl::IrregexpNumberOfRegisters(FixedArray* re) {
426 return Smi::cast(re->get(JSRegExp::kIrregexpMaxRegisterCountIndex))->value(); 432 return Smi::cast(re->get(JSRegExp::kIrregexpMaxRegisterCountIndex))->value();
427 } 433 }
428 434
(...skipping 6437 matching lines...) Expand 10 before | Expand all | Expand 10 after
6866 6872
6867 6873
6868 void RegExpResultsCache::Clear(FixedArray* cache) { 6874 void RegExpResultsCache::Clear(FixedArray* cache) {
6869 for (int i = 0; i < kRegExpResultsCacheSize; i++) { 6875 for (int i = 0; i < kRegExpResultsCacheSize; i++) {
6870 cache->set(i, Smi::FromInt(0)); 6876 cache->set(i, Smi::FromInt(0));
6871 } 6877 }
6872 } 6878 }
6873 6879
6874 } // namespace internal 6880 } // namespace internal
6875 } // namespace v8 6881 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698