| 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 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 ASSERT(args.length() == 4); | 1031 ASSERT(args.length() == 4); |
| 1032 CONVERT_CHECKED(JSRegExp, raw_regexp, args[0]); | 1032 CONVERT_CHECKED(JSRegExp, raw_regexp, args[0]); |
| 1033 Handle<JSRegExp> regexp(raw_regexp); | 1033 Handle<JSRegExp> regexp(raw_regexp); |
| 1034 CONVERT_CHECKED(String, raw_subject, args[1]); | 1034 CONVERT_CHECKED(String, raw_subject, args[1]); |
| 1035 Handle<String> subject(raw_subject); | 1035 Handle<String> subject(raw_subject); |
| 1036 // Due to the way the JS files are constructed this must be less than the | 1036 // Due to the way the JS files are constructed this must be less than the |
| 1037 // length of a string, i.e. it is always a Smi. We check anyway for security. | 1037 // length of a string, i.e. it is always a Smi. We check anyway for security. |
| 1038 CONVERT_CHECKED(Smi, index, args[2]); | 1038 CONVERT_CHECKED(Smi, index, args[2]); |
| 1039 CONVERT_CHECKED(JSArray, raw_last_match_info, args[3]); | 1039 CONVERT_CHECKED(JSArray, raw_last_match_info, args[3]); |
| 1040 Handle<JSArray> last_match_info(raw_last_match_info); | 1040 Handle<JSArray> last_match_info(raw_last_match_info); |
| 1041 CHECK(last_match_info->HasFastElements()); | 1041 RUNTIME_ASSERT(last_match_info->HasFastElements()); |
| 1042 RUNTIME_ASSERT(index->value() >= 0); |
| 1043 RUNTIME_ASSERT(index->value() <= subject->length()); |
| 1042 Handle<Object> result = RegExpImpl::Exec(regexp, | 1044 Handle<Object> result = RegExpImpl::Exec(regexp, |
| 1043 subject, | 1045 subject, |
| 1044 index->value(), | 1046 index->value(), |
| 1045 last_match_info); | 1047 last_match_info); |
| 1046 if (result.is_null()) return Failure::Exception(); | 1048 if (result.is_null()) return Failure::Exception(); |
| 1047 return *result; | 1049 return *result; |
| 1048 } | 1050 } |
| 1049 | 1051 |
| 1050 | 1052 |
| 1051 static Object* Runtime_RegExpExecGlobal(Arguments args) { | |
| 1052 HandleScope scope; | |
| 1053 ASSERT(args.length() == 3); | |
| 1054 CONVERT_CHECKED(JSRegExp, raw_regexp, args[0]); | |
| 1055 Handle<JSRegExp> regexp(raw_regexp); | |
| 1056 CONVERT_CHECKED(String, raw_subject, args[1]); | |
| 1057 Handle<String> subject(raw_subject); | |
| 1058 CONVERT_CHECKED(JSArray, raw_last_match_info, args[2]); | |
| 1059 Handle<JSArray> last_match_info(raw_last_match_info); | |
| 1060 CHECK(last_match_info->HasFastElements()); | |
| 1061 Handle<Object> result = | |
| 1062 RegExpImpl::ExecGlobal(regexp, subject, last_match_info); | |
| 1063 if (result.is_null()) return Failure::Exception(); | |
| 1064 return *result; | |
| 1065 } | |
| 1066 | |
| 1067 | |
| 1068 static Object* Runtime_MaterializeRegExpLiteral(Arguments args) { | 1053 static Object* Runtime_MaterializeRegExpLiteral(Arguments args) { |
| 1069 HandleScope scope; | 1054 HandleScope scope; |
| 1070 ASSERT(args.length() == 4); | 1055 ASSERT(args.length() == 4); |
| 1071 CONVERT_ARG_CHECKED(FixedArray, literals, 0); | 1056 CONVERT_ARG_CHECKED(FixedArray, literals, 0); |
| 1072 int index = Smi::cast(args[1])->value(); | 1057 int index = Smi::cast(args[1])->value(); |
| 1073 Handle<String> pattern = args.at<String>(2); | 1058 Handle<String> pattern = args.at<String>(2); |
| 1074 Handle<String> flags = args.at<String>(3); | 1059 Handle<String> flags = args.at<String>(3); |
| 1075 | 1060 |
| 1076 // Get the RegExp function from the context in the literals array. | 1061 // Get the RegExp function from the context in the literals array. |
| 1077 // This is the RegExp function from the context in which the | 1062 // This is the RegExp function from the context in which the |
| (...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2330 int start = FastD2I(from_number); | 2315 int start = FastD2I(from_number); |
| 2331 int end = FastD2I(to_number); | 2316 int end = FastD2I(to_number); |
| 2332 | 2317 |
| 2333 RUNTIME_ASSERT(end >= start); | 2318 RUNTIME_ASSERT(end >= start); |
| 2334 RUNTIME_ASSERT(start >= 0); | 2319 RUNTIME_ASSERT(start >= 0); |
| 2335 RUNTIME_ASSERT(end <= value->length()); | 2320 RUNTIME_ASSERT(end <= value->length()); |
| 2336 return value->Slice(start, end); | 2321 return value->Slice(start, end); |
| 2337 } | 2322 } |
| 2338 | 2323 |
| 2339 | 2324 |
| 2325 static Object* Runtime_StringMatch(Arguments args) { |
| 2326 ASSERT_EQ(3, args.length()); |
| 2327 |
| 2328 CONVERT_ARG_CHECKED(String, subject, 0); |
| 2329 CONVERT_ARG_CHECKED(JSRegExp, regexp, 1); |
| 2330 CONVERT_ARG_CHECKED(JSArray, regexp_info, 2); |
| 2331 HandleScope handles; |
| 2332 |
| 2333 Handle<Object> match = RegExpImpl::Exec(regexp, subject, 0, regexp_info); |
| 2334 |
| 2335 if (match.is_null()) { |
| 2336 return Failure::Exception(); |
| 2337 } |
| 2338 if (match->IsNull()) { |
| 2339 return Heap::null_value(); |
| 2340 } |
| 2341 int length = subject->length(); |
| 2342 |
| 2343 ZoneScope zone_space(DELETE_ON_EXIT); |
| 2344 ZoneList<int> offsets(8); |
| 2345 do { |
| 2346 int start; |
| 2347 int end; |
| 2348 { |
| 2349 AssertNoAllocation no_alloc; |
| 2350 FixedArray* elements = regexp_info->elements(); |
| 2351 start = Smi::cast(elements->get(RegExpImpl::kFirstCapture))->value(); |
| 2352 end = Smi::cast(elements->get(RegExpImpl::kFirstCapture + 1))->value(); |
| 2353 } |
| 2354 offsets.Add(start); |
| 2355 offsets.Add(end); |
| 2356 int index = start < end ? end : end + 1; |
| 2357 if (index > length) break; |
| 2358 match = RegExpImpl::Exec(regexp, subject, index, regexp_info); |
| 2359 if (match.is_null()) { |
| 2360 return Failure::Exception(); |
| 2361 } |
| 2362 } while (!match->IsNull()); |
| 2363 int matches = offsets.length() / 2; |
| 2364 Handle<FixedArray> elements = Factory::NewFixedArray(matches); |
| 2365 for (int i = 0; i < matches ; i++) { |
| 2366 int from = offsets.at(i * 2); |
| 2367 int to = offsets.at(i * 2 + 1); |
| 2368 elements->set(i, *Factory::NewStringSlice(subject, from, to)); |
| 2369 } |
| 2370 Handle<JSArray> result = Factory::NewJSArrayWithElements(elements); |
| 2371 result->set_length(Smi::FromInt(matches)); |
| 2372 return *result; |
| 2373 } |
| 2374 |
| 2375 |
| 2340 static Object* Runtime_NumberToRadixString(Arguments args) { | 2376 static Object* Runtime_NumberToRadixString(Arguments args) { |
| 2341 NoHandleAllocation ha; | 2377 NoHandleAllocation ha; |
| 2342 ASSERT(args.length() == 2); | 2378 ASSERT(args.length() == 2); |
| 2343 | 2379 |
| 2344 CONVERT_DOUBLE_CHECKED(value, args[0]); | 2380 CONVERT_DOUBLE_CHECKED(value, args[0]); |
| 2345 if (isnan(value)) { | 2381 if (isnan(value)) { |
| 2346 return Heap::AllocateStringFromAscii(CStrVector("NaN")); | 2382 return Heap::AllocateStringFromAscii(CStrVector("NaN")); |
| 2347 } | 2383 } |
| 2348 if (isinf(value)) { | 2384 if (isinf(value)) { |
| 2349 if (value < 0) { | 2385 if (value < 0) { |
| (...skipping 4542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6892 } else { | 6928 } else { |
| 6893 // Handle last resort GC and make sure to allow future allocations | 6929 // Handle last resort GC and make sure to allow future allocations |
| 6894 // to grow the heap without causing GCs (if possible). | 6930 // to grow the heap without causing GCs (if possible). |
| 6895 Counters::gc_last_resort_from_js.Increment(); | 6931 Counters::gc_last_resort_from_js.Increment(); |
| 6896 Heap::CollectAllGarbage(); | 6932 Heap::CollectAllGarbage(); |
| 6897 } | 6933 } |
| 6898 } | 6934 } |
| 6899 | 6935 |
| 6900 | 6936 |
| 6901 } } // namespace v8::internal | 6937 } } // namespace v8::internal |
| OLD | NEW |