| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/jsregexp-inl.h" | 8 #include "src/jsregexp-inl.h" |
| 9 #include "src/jsregexp.h" | 9 #include "src/jsregexp.h" |
| 10 #include "src/runtime/runtime-utils.h" | 10 #include "src/runtime/runtime-utils.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 for (int i = 0; i < end; i++) { | 274 for (int i = 0; i < end; i++) { |
| 275 if (flat1.Get(i) != flat2.Get(i)) { | 275 if (flat1.Get(i) != flat2.Get(i)) { |
| 276 return Smi::FromInt(flat1.Get(i) - flat2.Get(i)); | 276 return Smi::FromInt(flat1.Get(i) - flat2.Get(i)); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 return Smi::FromInt(str1_length - str2_length); | 280 return Smi::FromInt(str1_length - str2_length); |
| 281 } | 281 } |
| 282 | 282 |
| 283 | 283 |
| 284 RUNTIME_FUNCTION(Runtime_SubStringRT) { | 284 RUNTIME_FUNCTION(Runtime_SubString) { |
| 285 HandleScope scope(isolate); | 285 HandleScope scope(isolate); |
| 286 DCHECK(args.length() == 3); | 286 DCHECK(args.length() == 3); |
| 287 | 287 |
| 288 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); | 288 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); |
| 289 int start, end; | 289 int start, end; |
| 290 // We have a fast integer-only case here to avoid a conversion to double in | 290 // We have a fast integer-only case here to avoid a conversion to double in |
| 291 // the common case where from and to are Smis. | 291 // the common case where from and to are Smis. |
| 292 if (args[1]->IsSmi() && args[2]->IsSmi()) { | 292 if (args[1]->IsSmi() && args[2]->IsSmi()) { |
| 293 CONVERT_SMI_ARG_CHECKED(from_number, 1); | 293 CONVERT_SMI_ARG_CHECKED(from_number, 1); |
| 294 CONVERT_SMI_ARG_CHECKED(to_number, 2); | 294 CONVERT_SMI_ARG_CHECKED(to_number, 2); |
| 295 start = from_number; | 295 start = from_number; |
| 296 end = to_number; | 296 end = to_number; |
| 297 } else { | 297 } else { |
| 298 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1); | 298 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1); |
| 299 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2); | 299 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2); |
| 300 start = FastD2IChecked(from_number); | 300 start = FastD2IChecked(from_number); |
| 301 end = FastD2IChecked(to_number); | 301 end = FastD2IChecked(to_number); |
| 302 } | 302 } |
| 303 RUNTIME_ASSERT(end >= start); | 303 RUNTIME_ASSERT(end >= start); |
| 304 RUNTIME_ASSERT(start >= 0); | 304 RUNTIME_ASSERT(start >= 0); |
| 305 RUNTIME_ASSERT(end <= string->length()); | 305 RUNTIME_ASSERT(end <= string->length()); |
| 306 isolate->counters()->sub_string_runtime()->Increment(); | 306 isolate->counters()->sub_string_runtime()->Increment(); |
| 307 | 307 |
| 308 return *isolate->factory()->NewSubString(string, start, end); | 308 return *isolate->factory()->NewSubString(string, start, end); |
| 309 } | 309 } |
| 310 | 310 |
| 311 | 311 |
| 312 RUNTIME_FUNCTION(Runtime_SubString) { | 312 RUNTIME_FUNCTION(Runtime_StringAdd) { |
| 313 SealHandleScope shs(isolate); | |
| 314 return __RT_impl_Runtime_SubStringRT(args, isolate); | |
| 315 } | |
| 316 | |
| 317 | |
| 318 RUNTIME_FUNCTION(Runtime_StringAddRT) { | |
| 319 HandleScope scope(isolate); | 313 HandleScope scope(isolate); |
| 320 DCHECK(args.length() == 2); | 314 DCHECK(args.length() == 2); |
| 321 CONVERT_ARG_HANDLE_CHECKED(String, str1, 0); | 315 CONVERT_ARG_HANDLE_CHECKED(String, str1, 0); |
| 322 CONVERT_ARG_HANDLE_CHECKED(String, str2, 1); | 316 CONVERT_ARG_HANDLE_CHECKED(String, str2, 1); |
| 323 isolate->counters()->string_add_runtime()->Increment(); | 317 isolate->counters()->string_add_runtime()->Increment(); |
| 324 Handle<String> result; | 318 Handle<String> result; |
| 325 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 319 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 326 isolate, result, isolate->factory()->NewConsString(str1, str2)); | 320 isolate, result, isolate->factory()->NewConsString(str1, str2)); |
| 327 return *result; | 321 return *result; |
| 328 } | 322 } |
| 329 | 323 |
| 330 | 324 |
| 331 RUNTIME_FUNCTION(Runtime_StringAdd) { | |
| 332 SealHandleScope shs(isolate); | |
| 333 return __RT_impl_Runtime_StringAddRT(args, isolate); | |
| 334 } | |
| 335 | |
| 336 | |
| 337 RUNTIME_FUNCTION(Runtime_InternalizeString) { | 325 RUNTIME_FUNCTION(Runtime_InternalizeString) { |
| 338 HandleScope handles(isolate); | 326 HandleScope handles(isolate); |
| 339 RUNTIME_ASSERT(args.length() == 1); | 327 RUNTIME_ASSERT(args.length() == 1); |
| 340 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); | 328 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); |
| 341 return *isolate->factory()->InternalizeString(string); | 329 return *isolate->factory()->InternalizeString(string); |
| 342 } | 330 } |
| 343 | 331 |
| 344 | 332 |
| 345 RUNTIME_FUNCTION(Runtime_StringMatch) { | 333 RUNTIME_FUNCTION(Runtime_StringMatch) { |
| 346 HandleScope handles(isolate); | 334 HandleScope handles(isolate); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 DCHECK(args.length() == 1); | 409 DCHECK(args.length() == 1); |
| 422 if (args[0]->IsNumber()) { | 410 if (args[0]->IsNumber()) { |
| 423 CONVERT_NUMBER_CHECKED(uint32_t, code, Uint32, args[0]); | 411 CONVERT_NUMBER_CHECKED(uint32_t, code, Uint32, args[0]); |
| 424 code &= 0xffff; | 412 code &= 0xffff; |
| 425 return *isolate->factory()->LookupSingleCharacterStringFromCode(code); | 413 return *isolate->factory()->LookupSingleCharacterStringFromCode(code); |
| 426 } | 414 } |
| 427 return isolate->heap()->empty_string(); | 415 return isolate->heap()->empty_string(); |
| 428 } | 416 } |
| 429 | 417 |
| 430 | 418 |
| 431 RUNTIME_FUNCTION(Runtime_StringCompareRT) { | 419 RUNTIME_FUNCTION(Runtime_StringCompare) { |
| 432 HandleScope handle_scope(isolate); | 420 HandleScope handle_scope(isolate); |
| 433 DCHECK(args.length() == 2); | 421 DCHECK(args.length() == 2); |
| 434 | 422 |
| 435 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); | 423 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); |
| 436 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); | 424 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); |
| 437 | 425 |
| 438 isolate->counters()->string_compare_runtime()->Increment(); | 426 isolate->counters()->string_compare_runtime()->Increment(); |
| 439 | 427 |
| 440 // A few fast case tests before we flatten. | 428 // A few fast case tests before we flatten. |
| 441 if (x.is_identical_to(y)) return Smi::FromInt(EQUAL); | 429 if (x.is_identical_to(y)) return Smi::FromInt(EQUAL); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 Object* result; | 478 Object* result; |
| 491 if (r == 0) { | 479 if (r == 0) { |
| 492 result = equal_prefix_result; | 480 result = equal_prefix_result; |
| 493 } else { | 481 } else { |
| 494 result = (r < 0) ? Smi::FromInt(LESS) : Smi::FromInt(GREATER); | 482 result = (r < 0) ? Smi::FromInt(LESS) : Smi::FromInt(GREATER); |
| 495 } | 483 } |
| 496 return result; | 484 return result; |
| 497 } | 485 } |
| 498 | 486 |
| 499 | 487 |
| 500 RUNTIME_FUNCTION(Runtime_StringCompare) { | |
| 501 SealHandleScope shs(isolate); | |
| 502 return __RT_impl_Runtime_StringCompareRT(args, isolate); | |
| 503 } | |
| 504 | |
| 505 | |
| 506 RUNTIME_FUNCTION(Runtime_StringBuilderConcat) { | 488 RUNTIME_FUNCTION(Runtime_StringBuilderConcat) { |
| 507 HandleScope scope(isolate); | 489 HandleScope scope(isolate); |
| 508 DCHECK(args.length() == 3); | 490 DCHECK(args.length() == 3); |
| 509 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); | 491 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); |
| 510 int32_t array_length; | 492 int32_t array_length; |
| 511 if (!args[1]->ToInt32(&array_length)) { | 493 if (!args[1]->ToInt32(&array_length)) { |
| 512 THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewInvalidStringLengthError()); | 494 THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewInvalidStringLengthError()); |
| 513 } | 495 } |
| 514 CONVERT_ARG_HANDLE_CHECKED(String, special, 2); | 496 CONVERT_ARG_HANDLE_CHECKED(String, special, 2); |
| 515 | 497 |
| (...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 | 1328 |
| 1347 | 1329 |
| 1348 RUNTIME_FUNCTION(Runtime_StringGetLength) { | 1330 RUNTIME_FUNCTION(Runtime_StringGetLength) { |
| 1349 HandleScope scope(isolate); | 1331 HandleScope scope(isolate); |
| 1350 DCHECK(args.length() == 1); | 1332 DCHECK(args.length() == 1); |
| 1351 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); | 1333 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); |
| 1352 return Smi::FromInt(s->length()); | 1334 return Smi::FromInt(s->length()); |
| 1353 } | 1335 } |
| 1354 } // namespace internal | 1336 } // namespace internal |
| 1355 } // namespace v8 | 1337 } // namespace v8 |
| OLD | NEW |