OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/builtins/builtins.h" | 5 #include "src/builtins/builtins.h" |
6 #include "src/builtins/builtins-utils.h" | 6 #include "src/builtins/builtins-utils.h" |
7 | 7 |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 assembler->Return(assembler->NaNConstant()); | 470 assembler->Return(assembler->NaNConstant()); |
471 assembler->Bind(&if_positioninbounds); | 471 assembler->Bind(&if_positioninbounds); |
472 } | 472 } |
473 | 473 |
474 // Load the character at the {position} from the {receiver}. | 474 // Load the character at the {position} from the {receiver}. |
475 Node* value = assembler->StringCharCodeAt(receiver, position); | 475 Node* value = assembler->StringCharCodeAt(receiver, position); |
476 Node* result = assembler->SmiFromWord32(value); | 476 Node* result = assembler->SmiFromWord32(value); |
477 assembler->Return(result); | 477 assembler->Return(result); |
478 } | 478 } |
479 | 479 |
| 480 // ES6 section 21.1.3.12 String.prototype.normalize ( [form] ) |
| 481 // |
| 482 // Simply checks the argument is valid and returns the string itself. |
| 483 // If internationalization is enabled, then i18n.js will override this function |
| 484 // and provide the proper functionality, so this is just a fallback. |
| 485 BUILTIN(StringPrototypeNormalize) { |
| 486 HandleScope handle_scope(isolate); |
| 487 TO_THIS_STRING(string, "String.prototype.normalize"); |
| 488 |
| 489 Handle<Object> form_input = args.atOrUndefined(isolate, 1); |
| 490 if (form_input->IsUndefined(isolate)) return *string; |
| 491 |
| 492 Handle<String> form; |
| 493 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, form, |
| 494 Object::ToString(isolate, form_input)); |
| 495 |
| 496 if (!(String::Equals(form, |
| 497 isolate->factory()->NewStringFromStaticChars("NFC")) || |
| 498 String::Equals(form, |
| 499 isolate->factory()->NewStringFromStaticChars("NFD")) || |
| 500 String::Equals(form, |
| 501 isolate->factory()->NewStringFromStaticChars("NFKC")) || |
| 502 String::Equals(form, |
| 503 isolate->factory()->NewStringFromStaticChars("NFKD")))) { |
| 504 Handle<String> valid_forms = |
| 505 isolate->factory()->NewStringFromStaticChars("NFC, NFD, NFKC, NFKD"); |
| 506 THROW_NEW_ERROR_RETURN_FAILURE( |
| 507 isolate, |
| 508 NewRangeError(MessageTemplate::kNormalizationForm, valid_forms)); |
| 509 } |
| 510 |
| 511 return *string; |
| 512 } |
| 513 |
480 // ES6 section 21.1.3.25 String.prototype.toString () | 514 // ES6 section 21.1.3.25 String.prototype.toString () |
481 void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) { | 515 void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) { |
482 typedef compiler::Node Node; | 516 typedef compiler::Node Node; |
483 | 517 |
484 Node* receiver = assembler->Parameter(0); | 518 Node* receiver = assembler->Parameter(0); |
485 Node* context = assembler->Parameter(3); | 519 Node* context = assembler->Parameter(3); |
486 | 520 |
487 Node* result = assembler->ToThisValue( | 521 Node* result = assembler->ToThisValue( |
488 context, receiver, PrimitiveType::kString, "String.prototype.toString"); | 522 context, receiver, PrimitiveType::kString, "String.prototype.toString"); |
489 assembler->Return(result); | 523 assembler->Return(result); |
(...skipping 27 matching lines...) Expand all Loading... |
517 Node* receiver = assembler->Parameter(0); | 551 Node* receiver = assembler->Parameter(0); |
518 Node* context = assembler->Parameter(3); | 552 Node* context = assembler->Parameter(3); |
519 | 553 |
520 Node* result = assembler->ToThisValue( | 554 Node* result = assembler->ToThisValue( |
521 context, receiver, PrimitiveType::kString, "String.prototype.valueOf"); | 555 context, receiver, PrimitiveType::kString, "String.prototype.valueOf"); |
522 assembler->Return(result); | 556 assembler->Return(result); |
523 } | 557 } |
524 | 558 |
525 } // namespace internal | 559 } // namespace internal |
526 } // namespace v8 | 560 } // namespace v8 |
OLD | NEW |