Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 // from the source pattern. | 288 // from the source pattern. |
| 289 // If compilation fails, an exception is thrown and this function | 289 // If compilation fails, an exception is thrown and this function |
| 290 // returns false. | 290 // returns false. |
| 291 bool RegExpImpl::EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii) { | 291 bool RegExpImpl::EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii) { |
| 292 Object* compiled_code = re->DataAt(JSRegExp::code_index(is_ascii)); | 292 Object* compiled_code = re->DataAt(JSRegExp::code_index(is_ascii)); |
| 293 #ifdef V8_INTERPRETED_REGEXP | 293 #ifdef V8_INTERPRETED_REGEXP |
| 294 if (compiled_code->IsByteArray()) return true; | 294 if (compiled_code->IsByteArray()) return true; |
| 295 #else // V8_INTERPRETED_REGEXP (RegExp native code) | 295 #else // V8_INTERPRETED_REGEXP (RegExp native code) |
| 296 if (compiled_code->IsCode()) return true; | 296 if (compiled_code->IsCode()) return true; |
| 297 #endif | 297 #endif |
| 298 // We could potentially have marked this as flushable, but have kept | |
| 299 // a saved version if we did not flush it yet. | |
| 300 Object* saved_code = re->DataAt(JSRegExp::saved_code_index(is_ascii)); | |
| 301 if (saved_code->IsCode()) { | |
| 302 // Reinstate the code in the original place. | |
| 303 re->SetDataAt(JSRegExp::code_index(is_ascii), saved_code); | |
| 304 ASSERT(compiled_code->IsSmi()); | |
| 305 return true; | |
| 306 } | |
| 298 return CompileIrregexp(re, is_ascii); | 307 return CompileIrregexp(re, is_ascii); |
| 299 } | 308 } |
| 300 | 309 |
| 301 | 310 |
| 302 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_ascii) { | 311 bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_ascii) { |
| 303 // Compile the RegExp. | 312 // Compile the RegExp. |
| 304 Isolate* isolate = re->GetIsolate(); | 313 Isolate* isolate = re->GetIsolate(); |
| 305 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 314 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); |
| 306 PostponeInterruptsScope postpone(isolate); | 315 PostponeInterruptsScope postpone(isolate); |
| 316 // If we had a compilation error the last time this is saved at the | |
| 317 // saved code index. | |
| 307 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); | 318 Object* entry = re->DataAt(JSRegExp::code_index(is_ascii)); |
| 308 if (entry->IsJSObject()) { | 319 // When arriving here entry can only be a smi, either representing an |
| 309 // If it's a JSObject, a previous compilation failed and threw this object. | 320 // uncompiled regexp, a previous compilation error, or code that has |
| 310 // Re-throw the object without trying again. | 321 // been flushed. |
| 311 isolate->Throw(entry); | 322 ASSERT(entry->IsSmi()); |
| 323 int entry_value = Smi::cast(entry)->value(); | |
| 324 ASSERT(entry_value == JSRegExp::kUninitializedValue || | |
| 325 entry_value == JSRegExp::kCompilationErrorValue || | |
| 326 (entry_value < JSRegExp::kCodeAgeMask && entry_value >= 0)); | |
| 327 | |
| 328 if (entry_value == JSRegExp::kCompilationErrorValue) { | |
| 329 // A previous compilation failed and threw an error which we store in | |
| 330 // the saved code index. We rethrow the error which we never flush. | |
| 331 Object* error = re->DataAt(JSRegExp::saved_code_index(is_ascii)); | |
| 332 ASSERT(error->IsJSObject()); | |
| 333 isolate->Throw(error); | |
| 312 return false; | 334 return false; |
| 313 } | 335 } |
| 314 ASSERT(entry->IsTheHole()); | |
| 315 | 336 |
| 316 JSRegExp::Flags flags = re->GetFlags(); | 337 JSRegExp::Flags flags = re->GetFlags(); |
| 317 | 338 |
| 318 Handle<String> pattern(re->Pattern()); | 339 Handle<String> pattern(re->Pattern()); |
| 319 if (!pattern->IsFlat()) { | 340 if (!pattern->IsFlat()) { |
| 320 FlattenString(pattern); | 341 FlattenString(pattern); |
| 321 } | 342 } |
| 322 | 343 |
| 323 RegExpCompileData compile_data; | 344 RegExpCompileData compile_data; |
| 324 FlatStringReader reader(isolate, pattern); | 345 FlatStringReader reader(isolate, pattern); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 343 Factory* factory = isolate->factory(); | 364 Factory* factory = isolate->factory(); |
| 344 Handle<FixedArray> elements = factory->NewFixedArray(2); | 365 Handle<FixedArray> elements = factory->NewFixedArray(2); |
| 345 elements->set(0, *pattern); | 366 elements->set(0, *pattern); |
| 346 Handle<String> error_message = | 367 Handle<String> error_message = |
| 347 factory->NewStringFromUtf8(CStrVector(result.error_message)); | 368 factory->NewStringFromUtf8(CStrVector(result.error_message)); |
| 348 elements->set(1, *error_message); | 369 elements->set(1, *error_message); |
| 349 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); | 370 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
| 350 Handle<Object> regexp_err = | 371 Handle<Object> regexp_err = |
| 351 factory->NewSyntaxError("malformed_regexp", array); | 372 factory->NewSyntaxError("malformed_regexp", array); |
| 352 isolate->Throw(*regexp_err); | 373 isolate->Throw(*regexp_err); |
| 353 re->SetDataAt(JSRegExp::code_index(is_ascii), *regexp_err); | 374 // Put the error object into the saved_code index, and put the |
| 375 // kCompilationErrorValue into the code index. This way, the fast | |
| 376 // case code only needs to check the code. | |
| 377 re->SetDataAt(JSRegExp::saved_code_index(is_ascii), *regexp_err); | |
|
Erik Corry
2011/07/01 09:05:23
Shouldn't you be setting the kCompilationErrorValu
Rico
2011/07/01 09:38:26
Done.
| |
| 354 return false; | 378 return false; |
| 355 } | 379 } |
| 356 | 380 |
| 357 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data())); | 381 Handle<FixedArray> data = Handle<FixedArray>(FixedArray::cast(re->data())); |
| 358 data->set(JSRegExp::code_index(is_ascii), result.code); | 382 data->set(JSRegExp::code_index(is_ascii), result.code); |
| 359 int register_max = IrregexpMaxRegisterCount(*data); | 383 int register_max = IrregexpMaxRegisterCount(*data); |
| 360 if (result.num_registers > register_max) { | 384 if (result.num_registers > register_max) { |
| 361 SetIrregexpMaxRegisterCount(*data, result.num_registers); | 385 SetIrregexpMaxRegisterCount(*data, result.num_registers); |
| 362 } | 386 } |
| 363 | 387 |
| (...skipping 4967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5331 } | 5355 } |
| 5332 | 5356 |
| 5333 return compiler.Assemble(¯o_assembler, | 5357 return compiler.Assemble(¯o_assembler, |
| 5334 node, | 5358 node, |
| 5335 data->capture_count, | 5359 data->capture_count, |
| 5336 pattern); | 5360 pattern); |
| 5337 } | 5361 } |
| 5338 | 5362 |
| 5339 | 5363 |
| 5340 }} // namespace v8::internal | 5364 }} // namespace v8::internal |
| OLD | NEW |