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

Side by Side Diff: test/cctest/test-regexp.cc

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed rest Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #include "ia32/macro-assembler-ia32.h" 64 #include "ia32/macro-assembler-ia32.h"
65 #include "ia32/regexp-macro-assembler-ia32.h" 65 #include "ia32/regexp-macro-assembler-ia32.h"
66 #endif 66 #endif
67 #endif // V8_INTERPRETED_REGEXP 67 #endif // V8_INTERPRETED_REGEXP
68 68
69 using namespace v8::internal; 69 using namespace v8::internal;
70 70
71 71
72 static bool CheckParse(const char* input) { 72 static bool CheckParse(const char* input) {
73 V8::Initialize(NULL); 73 V8::Initialize(NULL);
74 v8::HandleScope scope; 74 v8::HandleScope scope(v8::Isolate::GetCurrent());
75 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); 75 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT);
76 FlatStringReader reader(Isolate::Current(), CStrVector(input)); 76 FlatStringReader reader(Isolate::Current(), CStrVector(input));
77 RegExpCompileData result; 77 RegExpCompileData result;
78 return v8::internal::RegExpParser::ParseRegExp( 78 return v8::internal::RegExpParser::ParseRegExp(
79 &reader, false, &result, Isolate::Current()->runtime_zone()); 79 &reader, false, &result, Isolate::Current()->runtime_zone());
80 } 80 }
81 81
82 82
83 static SmartArrayPointer<const char> Parse(const char* input) { 83 static SmartArrayPointer<const char> Parse(const char* input) {
84 V8::Initialize(NULL); 84 V8::Initialize(NULL);
85 v8::HandleScope scope; 85 v8::HandleScope scope(v8::Isolate::GetCurrent());
86 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); 86 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT);
87 FlatStringReader reader(Isolate::Current(), CStrVector(input)); 87 FlatStringReader reader(Isolate::Current(), CStrVector(input));
88 RegExpCompileData result; 88 RegExpCompileData result;
89 CHECK(v8::internal::RegExpParser::ParseRegExp( 89 CHECK(v8::internal::RegExpParser::ParseRegExp(
90 &reader, false, &result, Isolate::Current()->runtime_zone())); 90 &reader, false, &result, Isolate::Current()->runtime_zone()));
91 CHECK(result.tree != NULL); 91 CHECK(result.tree != NULL);
92 CHECK(result.error.is_null()); 92 CHECK(result.error.is_null());
93 SmartArrayPointer<const char> output = 93 SmartArrayPointer<const char> output =
94 result.tree->ToString(Isolate::Current()->runtime_zone()); 94 result.tree->ToString(Isolate::Current()->runtime_zone());
95 return output; 95 return output;
96 } 96 }
97 97
98 static bool CheckSimple(const char* input) { 98 static bool CheckSimple(const char* input) {
99 V8::Initialize(NULL); 99 V8::Initialize(NULL);
100 v8::HandleScope scope; 100 v8::HandleScope scope(v8::Isolate::GetCurrent());
101 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); 101 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT);
102 FlatStringReader reader(Isolate::Current(), CStrVector(input)); 102 FlatStringReader reader(Isolate::Current(), CStrVector(input));
103 RegExpCompileData result; 103 RegExpCompileData result;
104 CHECK(v8::internal::RegExpParser::ParseRegExp( 104 CHECK(v8::internal::RegExpParser::ParseRegExp(
105 &reader, false, &result, Isolate::Current()->runtime_zone())); 105 &reader, false, &result, Isolate::Current()->runtime_zone()));
106 CHECK(result.tree != NULL); 106 CHECK(result.tree != NULL);
107 CHECK(result.error.is_null()); 107 CHECK(result.error.is_null());
108 return result.simple; 108 return result.simple;
109 } 109 }
110 110
111 struct MinMaxPair { 111 struct MinMaxPair {
112 int min_match; 112 int min_match;
113 int max_match; 113 int max_match;
114 }; 114 };
115 115
116 static MinMaxPair CheckMinMaxMatch(const char* input) { 116 static MinMaxPair CheckMinMaxMatch(const char* input) {
117 V8::Initialize(NULL); 117 V8::Initialize(NULL);
118 v8::HandleScope scope; 118 v8::HandleScope scope(v8::Isolate::GetCurrent());
119 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); 119 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT);
120 FlatStringReader reader(Isolate::Current(), CStrVector(input)); 120 FlatStringReader reader(Isolate::Current(), CStrVector(input));
121 RegExpCompileData result; 121 RegExpCompileData result;
122 CHECK(v8::internal::RegExpParser::ParseRegExp( 122 CHECK(v8::internal::RegExpParser::ParseRegExp(
123 &reader, false, &result, Isolate::Current()->runtime_zone())); 123 &reader, false, &result, Isolate::Current()->runtime_zone()));
124 CHECK(result.tree != NULL); 124 CHECK(result.tree != NULL);
125 CHECK(result.error.is_null()); 125 CHECK(result.error.is_null());
126 int min_match = result.tree->min_match(); 126 int min_match = result.tree->min_match();
127 int max_match = result.tree->max_match(); 127 int max_match = result.tree->max_match();
128 MinMaxPair pair = { min_match, max_match }; 128 MinMaxPair pair = { min_match, max_match };
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 TEST(ParserRegression) { 381 TEST(ParserRegression) {
382 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); 382 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])");
383 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); 383 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')");
384 CHECK_PARSE_EQ("{", "'{'"); 384 CHECK_PARSE_EQ("{", "'{'");
385 CHECK_PARSE_EQ("a|", "(| 'a' %)"); 385 CHECK_PARSE_EQ("a|", "(| 'a' %)");
386 } 386 }
387 387
388 static void ExpectError(const char* input, 388 static void ExpectError(const char* input,
389 const char* expected) { 389 const char* expected) {
390 V8::Initialize(NULL); 390 V8::Initialize(NULL);
391 v8::HandleScope scope; 391 v8::HandleScope scope(v8::Isolate::GetCurrent());
392 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); 392 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT);
393 FlatStringReader reader(Isolate::Current(), CStrVector(input)); 393 FlatStringReader reader(Isolate::Current(), CStrVector(input));
394 RegExpCompileData result; 394 RegExpCompileData result;
395 CHECK(!v8::internal::RegExpParser::ParseRegExp( 395 CHECK(!v8::internal::RegExpParser::ParseRegExp(
396 &reader, false, &result, Isolate::Current()->runtime_zone())); 396 &reader, false, &result, Isolate::Current()->runtime_zone()));
397 CHECK(result.tree == NULL); 397 CHECK(result.tree == NULL);
398 CHECK(!result.error.is_null()); 398 CHECK(!result.error.is_null());
399 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS); 399 SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS);
400 CHECK_EQ(expected, *str); 400 CHECK_EQ(expected, *str);
401 } 401 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 is_ascii, 523 is_ascii,
524 isolate->runtime_zone()); 524 isolate->runtime_zone());
525 return compile_data.node; 525 return compile_data.node;
526 } 526 }
527 527
528 528
529 static void Execute(const char* input, 529 static void Execute(const char* input,
530 bool multiline, 530 bool multiline,
531 bool is_ascii, 531 bool is_ascii,
532 bool dot_output = false) { 532 bool dot_output = false) {
533 v8::HandleScope scope; 533 v8::HandleScope scope(v8::Isolate::GetCurrent());
534 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); 534 ZoneScope zone_scope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT);
535 RegExpNode* node = Compile(input, multiline, is_ascii); 535 RegExpNode* node = Compile(input, multiline, is_ascii);
536 USE(node); 536 USE(node);
537 #ifdef DEBUG 537 #ifdef DEBUG
538 if (dot_output) { 538 if (dot_output) {
539 RegExpEngine::DotPrint(input, node, false); 539 RegExpEngine::DotPrint(input, node, false);
540 exit(0); 540 exit(0);
541 } 541 }
542 #endif // DEBUG 542 #endif // DEBUG
543 } 543 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 typedef RegExpMacroAssemblerX64 ArchRegExpMacroAssembler; 700 typedef RegExpMacroAssemblerX64 ArchRegExpMacroAssembler;
701 #elif V8_TARGET_ARCH_ARM 701 #elif V8_TARGET_ARCH_ARM
702 typedef RegExpMacroAssemblerARM ArchRegExpMacroAssembler; 702 typedef RegExpMacroAssemblerARM ArchRegExpMacroAssembler;
703 #elif V8_TARGET_ARCH_MIPS 703 #elif V8_TARGET_ARCH_MIPS
704 typedef RegExpMacroAssemblerMIPS ArchRegExpMacroAssembler; 704 typedef RegExpMacroAssemblerMIPS ArchRegExpMacroAssembler;
705 #endif 705 #endif
706 706
707 class ContextInitializer { 707 class ContextInitializer {
708 public: 708 public:
709 ContextInitializer() 709 ContextInitializer()
710 : env_(), scope_(), zone_(Isolate::Current()->runtime_zone(), 710 : env_(),
711 DELETE_ON_EXIT) { 711 scope_(v8::Isolate::GetCurrent()),
712 zone_(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT) {
712 env_ = v8::Context::New(); 713 env_ = v8::Context::New();
713 env_->Enter(); 714 env_->Enter();
714 } 715 }
715 ~ContextInitializer() { 716 ~ContextInitializer() {
716 env_->Exit(); 717 env_->Exit();
717 env_.Dispose(env_->GetIsolate()); 718 env_.Dispose(env_->GetIsolate());
718 } 719 }
719 private: 720 private:
720 v8::Persistent<v8::Context> env_; 721 v8::Persistent<v8::Context> env_;
721 v8::HandleScope scope_; 722 v8::HandleScope scope_;
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 ZoneList<CharacterRange> first_only(4, Isolate::Current()->runtime_zone()); 1801 ZoneList<CharacterRange> first_only(4, Isolate::Current()->runtime_zone());
1801 ZoneList<CharacterRange> second_only(4, Isolate::Current()->runtime_zone()); 1802 ZoneList<CharacterRange> second_only(4, Isolate::Current()->runtime_zone());
1802 ZoneList<CharacterRange> both(4, Isolate::Current()->runtime_zone()); 1803 ZoneList<CharacterRange> both(4, Isolate::Current()->runtime_zone());
1803 } 1804 }
1804 1805
1805 1806
1806 TEST(Graph) { 1807 TEST(Graph) {
1807 V8::Initialize(NULL); 1808 V8::Initialize(NULL);
1808 Execute("\\b\\w+\\b", false, true, true); 1809 Execute("\\b\\w+\\b", false, true, true);
1809 } 1810 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698