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

Side by Side Diff: src/jsregexp.cc

Issue 2866008: [Isolates] Move contents of Top into Isolate.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: ensure we're synced Created 10 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 | Annotate | Revision Log
« no previous file with comments | « src/isolate.cc ('k') | src/liveedit.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 16 matching lines...) Expand all
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "ast.h" 30 #include "ast.h"
31 #include "compiler.h" 31 #include "compiler.h"
32 #include "execution.h" 32 #include "execution.h"
33 #include "factory.h" 33 #include "factory.h"
34 #include "jsregexp.h" 34 #include "jsregexp.h"
35 #include "platform.h" 35 #include "platform.h"
36 #include "runtime.h" 36 #include "runtime.h"
37 #include "top.h"
38 #include "compilation-cache.h" 37 #include "compilation-cache.h"
39 #include "string-stream.h" 38 #include "string-stream.h"
40 #include "parser.h" 39 #include "parser.h"
41 #include "regexp-macro-assembler.h" 40 #include "regexp-macro-assembler.h"
42 #include "regexp-macro-assembler-tracer.h" 41 #include "regexp-macro-assembler-tracer.h"
43 #include "regexp-macro-assembler-irregexp.h" 42 #include "regexp-macro-assembler-irregexp.h"
44 #include "regexp-stack.h" 43 #include "regexp-stack.h"
45 44
46 #ifndef V8_INTERPRETED_REGEXP 45 #ifndef V8_INTERPRETED_REGEXP
47 #if V8_TARGET_ARCH_IA32 46 #if V8_TARGET_ARCH_IA32
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 92
94 93
95 static inline void ThrowRegExpException(Handle<JSRegExp> re, 94 static inline void ThrowRegExpException(Handle<JSRegExp> re,
96 Handle<String> pattern, 95 Handle<String> pattern,
97 Handle<String> error_text, 96 Handle<String> error_text,
98 const char* message) { 97 const char* message) {
99 Handle<JSArray> array = Factory::NewJSArray(2); 98 Handle<JSArray> array = Factory::NewJSArray(2);
100 SetElement(array, 0, pattern); 99 SetElement(array, 0, pattern);
101 SetElement(array, 1, error_text); 100 SetElement(array, 1, error_text);
102 Handle<Object> regexp_err = Factory::NewSyntaxError(message, array); 101 Handle<Object> regexp_err = Factory::NewSyntaxError(message, array);
103 Top::Throw(*regexp_err); 102 Isolate::Current()->Throw(*regexp_err);
104 } 103 }
105 104
106 105
107 // Generic RegExp methods. Dispatches to implementation specific methods. 106 // Generic RegExp methods. Dispatches to implementation specific methods.
108 107
109 108
110 Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, 109 Handle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
111 Handle<String> pattern, 110 Handle<String> pattern,
112 Handle<String> flag_str) { 111 Handle<String> flag_str) {
113 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); 112 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 Handle<Object> RegExpImpl::Exec(Handle<JSRegExp> regexp, 160 Handle<Object> RegExpImpl::Exec(Handle<JSRegExp> regexp,
162 Handle<String> subject, 161 Handle<String> subject,
163 int index, 162 int index,
164 Handle<JSArray> last_match_info) { 163 Handle<JSArray> last_match_info) {
165 switch (regexp->TypeTag()) { 164 switch (regexp->TypeTag()) {
166 case JSRegExp::ATOM: 165 case JSRegExp::ATOM:
167 return AtomExec(regexp, subject, index, last_match_info); 166 return AtomExec(regexp, subject, index, last_match_info);
168 case JSRegExp::IRREGEXP: { 167 case JSRegExp::IRREGEXP: {
169 Handle<Object> result = 168 Handle<Object> result =
170 IrregexpExec(regexp, subject, index, last_match_info); 169 IrregexpExec(regexp, subject, index, last_match_info);
171 ASSERT(!result.is_null() || Top::has_pending_exception()); 170 ASSERT(!result.is_null() || Isolate::Current()->has_pending_exception());
172 return result; 171 return result;
173 } 172 }
174 default: 173 default:
175 UNREACHABLE(); 174 UNREACHABLE();
176 return Handle<Object>::null(); 175 return Handle<Object>::null();
177 } 176 }
178 } 177 }
179 178
180 179
181 // RegExp Atom implementation: Simple string search using indexOf. 180 // RegExp Atom implementation: Simple string search using indexOf.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 246
248 247
249 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_ascii) { 248 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_ascii) {
250 // Compile the RegExp. 249 // Compile the RegExp.
251 CompilationZoneScope zone_scope(DELETE_ON_EXIT); 250 CompilationZoneScope zone_scope(DELETE_ON_EXIT);
252 PostponeInterruptsScope postpone; 251 PostponeInterruptsScope postpone;
253 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); 252 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii));
254 if (entry->IsJSObject()) { 253 if (entry->IsJSObject()) {
255 // If it's a JSObject, a previous compilation failed and threw this object. 254 // If it's a JSObject, a previous compilation failed and threw this object.
256 // Re-throw the object without trying again. 255 // Re-throw the object without trying again.
257 Top::Throw(entry); 256 Isolate::Current()->Throw(entry);
258 return false; 257 return false;
259 } 258 }
260 ASSERT(entry->IsTheHole()); 259 ASSERT(entry->IsTheHole());
261 260
262 JSRegExp::Flags flags = re->GetFlags(); 261 JSRegExp::Flags flags = re->GetFlags();
263 262
264 Handle<String> pattern(re->Pattern()); 263 Handle<String> pattern(re->Pattern());
265 if (!pattern->IsFlat()) { 264 if (!pattern->IsFlat()) {
266 FlattenString(pattern); 265 FlattenString(pattern);
267 } 266 }
(...skipping 17 matching lines...) Expand all
285 is_ascii); 284 is_ascii);
286 if (result.error_message != NULL) { 285 if (result.error_message != NULL) {
287 // Unable to compile regexp. 286 // Unable to compile regexp.
288 Handle<JSArray> array = Factory::NewJSArray(2); 287 Handle<JSArray> array = Factory::NewJSArray(2);
289 SetElement(array, 0, pattern); 288 SetElement(array, 0, pattern);
290 SetElement(array, 289 SetElement(array,
291 1, 290 1,
292 Factory::NewStringFromUtf8(CStrVector(result.error_message))); 291 Factory::NewStringFromUtf8(CStrVector(result.error_message)));
293 Handle<Object> regexp_err = 292 Handle<Object> regexp_err =
294 Factory::NewSyntaxError("malformed_regexp", array); 293 Factory::NewSyntaxError("malformed_regexp", array);
295 Top::Throw(*regexp_err); 294 Isolate::Current()->Throw(*regexp_err);
296 re->SetDataAt(JSRegExp::code_index(is_ascii), *regexp_err); 295 re->SetDataAt(JSRegExp::code_index(is_ascii), *regexp_err);
297 return false; 296 return false;
298 } 297 }
299 298
300 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data())); 299 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data()));
301 data->set(JSRegExp::code_index(is_ascii), result.code); 300 data->set(JSRegExp::code_index(is_ascii), result.code);
302 int register_max = IrregexpMaxRegisterCount(*data); 301 int register_max = IrregexpMaxRegisterCount(*data);
303 if (result.num_registers > register_max) { 302 if (result.num_registers > register_max) {
304 SetIrregexpMaxRegisterCount(*data, result.num_registers); 303 SetIrregexpMaxRegisterCount(*data, result.num_registers);
305 } 304 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 bool is_ascii = subject->IsAsciiRepresentation(); 388 bool is_ascii = subject->IsAsciiRepresentation();
390 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii)); 389 Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii));
391 NativeRegExpMacroAssembler::Result res = 390 NativeRegExpMacroAssembler::Result res =
392 NativeRegExpMacroAssembler::Match(code, 391 NativeRegExpMacroAssembler::Match(code,
393 subject, 392 subject,
394 output.start(), 393 output.start(),
395 output.length(), 394 output.length(),
396 index); 395 index);
397 if (res != NativeRegExpMacroAssembler::RETRY) { 396 if (res != NativeRegExpMacroAssembler::RETRY) {
398 ASSERT(res != NativeRegExpMacroAssembler::EXCEPTION || 397 ASSERT(res != NativeRegExpMacroAssembler::EXCEPTION ||
399 Top::has_pending_exception()); 398 Isolate::Current()->has_pending_exception());
400 STATIC_ASSERT( 399 STATIC_ASSERT(
401 static_cast<int>(NativeRegExpMacroAssembler::SUCCESS) == RE_SUCCESS); 400 static_cast<int>(NativeRegExpMacroAssembler::SUCCESS) == RE_SUCCESS);
402 STATIC_ASSERT( 401 STATIC_ASSERT(
403 static_cast<int>(NativeRegExpMacroAssembler::FAILURE) == RE_FAILURE); 402 static_cast<int>(NativeRegExpMacroAssembler::FAILURE) == RE_FAILURE);
404 STATIC_ASSERT(static_cast<int>(NativeRegExpMacroAssembler::EXCEPTION) 403 STATIC_ASSERT(static_cast<int>(NativeRegExpMacroAssembler::EXCEPTION)
405 == RE_EXCEPTION); 404 == RE_EXCEPTION);
406 return static_cast<IrregexpResult>(res); 405 return static_cast<IrregexpResult>(res);
407 } 406 }
408 // If result is RETRY, the string has changed representation, and we 407 // If result is RETRY, the string has changed representation, and we
409 // must restart from scratch. 408 // must restart from scratch.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 if (FLAG_trace_regexp_bytecodes) { 451 if (FLAG_trace_regexp_bytecodes) {
453 String* pattern = jsregexp->Pattern(); 452 String* pattern = jsregexp->Pattern();
454 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString())); 453 PrintF("\n\nRegexp match: /%s/\n\n", *(pattern->ToCString()));
455 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString())); 454 PrintF("\n\nSubject string: '%s'\n\n", *(subject->ToCString()));
456 } 455 }
457 #endif 456 #endif
458 #endif 457 #endif
459 int required_registers = RegExpImpl::IrregexpPrepare(jsregexp, subject); 458 int required_registers = RegExpImpl::IrregexpPrepare(jsregexp, subject);
460 if (required_registers < 0) { 459 if (required_registers < 0) {
461 // Compiling failed with an exception. 460 // Compiling failed with an exception.
462 ASSERT(Top::has_pending_exception()); 461 ASSERT(Isolate::Current()->has_pending_exception());
463 return Handle<Object>::null(); 462 return Handle<Object>::null();
464 } 463 }
465 464
466 OffsetsVector registers(required_registers); 465 OffsetsVector registers(required_registers);
467 466
468 IrregexpResult res = IrregexpExecOnce(jsregexp, 467 IrregexpResult res = IrregexpExecOnce(jsregexp,
469 subject, 468 subject,
470 previous_index, 469 previous_index,
471 Vector<int>(registers.vector(), 470 Vector<int>(registers.vector(),
472 registers.length())); 471 registers.length()));
473 if (res == RE_SUCCESS) { 472 if (res == RE_SUCCESS) {
474 int capture_register_count = 473 int capture_register_count =
475 (IrregexpNumberOfCaptures(FixedArray::cast(jsregexp->data())) + 1) * 2; 474 (IrregexpNumberOfCaptures(FixedArray::cast(jsregexp->data())) + 1) * 2;
476 last_match_info->EnsureSize(capture_register_count + kLastMatchOverhead); 475 last_match_info->EnsureSize(capture_register_count + kLastMatchOverhead);
477 AssertNoAllocation no_gc; 476 AssertNoAllocation no_gc;
478 int* register_vector = registers.vector(); 477 int* register_vector = registers.vector();
479 FixedArray* array = FixedArray::cast(last_match_info->elements()); 478 FixedArray* array = FixedArray::cast(last_match_info->elements());
480 for (int i = 0; i < capture_register_count; i += 2) { 479 for (int i = 0; i < capture_register_count; i += 2) {
481 SetCapture(array, i, register_vector[i]); 480 SetCapture(array, i, register_vector[i]);
482 SetCapture(array, i + 1, register_vector[i + 1]); 481 SetCapture(array, i + 1, register_vector[i + 1]);
483 } 482 }
484 SetLastCaptureCount(array, capture_register_count); 483 SetLastCaptureCount(array, capture_register_count);
485 SetLastSubject(array, *subject); 484 SetLastSubject(array, *subject);
486 SetLastInput(array, *subject); 485 SetLastInput(array, *subject);
487 return last_match_info; 486 return last_match_info;
488 } 487 }
489 if (res == RE_EXCEPTION) { 488 if (res == RE_EXCEPTION) {
490 ASSERT(Top::has_pending_exception()); 489 ASSERT(Isolate::Current()->has_pending_exception());
491 return Handle<Object>::null(); 490 return Handle<Object>::null();
492 } 491 }
493 ASSERT(res == RE_FAILURE); 492 ASSERT(res == RE_FAILURE);
494 return Factory::null_value(); 493 return Factory::null_value();
495 } 494 }
496 495
497 496
498 // ------------------------------------------------------------------- 497 // -------------------------------------------------------------------
499 // Implementation of the Irregexp regular expression engine. 498 // Implementation of the Irregexp regular expression engine.
500 // 499 //
(...skipping 4758 matching lines...) Expand 10 before | Expand all | Expand 10 after
5259 node, 5258 node,
5260 data->capture_count, 5259 data->capture_count,
5261 pattern); 5260 pattern);
5262 } 5261 }
5263 5262
5264 5263
5265 int OffsetsVector::static_offsets_vector_[ 5264 int OffsetsVector::static_offsets_vector_[
5266 OffsetsVector::kStaticOffsetsVectorSize]; 5265 OffsetsVector::kStaticOffsetsVectorSize];
5267 5266
5268 }} // namespace v8::internal 5267 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/liveedit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698